C++ examples for Data Type:float
Uses the fabs() function to compute the difference between two ages.
#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; }