Uses the fabs() function to compute the difference between two ages. - C++ Data Type

C++ examples for Data Type:float

Description

Uses the fabs() function to compute the difference between two ages.

Demo Code

#include <iostream>
using namespace std;
#include <math.h>
void main()//ww w . ja  v a2 s  .com
{
   float age1, age2, diff;
   cout << "\nWhat is the first child's age? ";
   cin >> age1;
   cout << "What is the second child's age? ";
   cin >> age2;

   diff = age1 - age2;
   diff = fabs(diff);     
   cout << "\nThey are " << diff << " years apart.";
   return;
}

Result


Related Tutorials