C++ float type compute the difference between two ages.

Description

C++ float type compute the difference between two ages.

#include <iostream>
using namespace std;
#include <math.h>
void main()/*w  ww.ja va2  s. c om*/
{
   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;
}



PreviousNext

Related