< previous page page_168 next page >

Page 168
    cout.setf(ios::fixed, ios::floatfield);   // Set up floating pt.
    cout.setf(ios::showpoint);                //   output format

    // Get data

    cout << Enter the lengths of the two sides. << endl;
    cin >> lengthOfA >> lengthOfB;

    // Print data

    cout << endl;
    cout << The length of side A is 
         << setw(8) << setprecision(4) << lengthOfA << endl;
    cout << The length of side B is 
         << setw(8) << lengthOfB << endl;

    // Compute sum of squares

    sumOfSquares = lengthOfA * lengthOfA + lengthOfB * lengthOfB;

    // Find length of hypotenuse

    hypotenuse = sqrt(sumOfSquares);

    // Print length of hypotenuse

    cout << The length of the hypotenuse is 
         << hypotenuse << endl;
    return 0;
}
This is an interactive program. The data is input while the program is executing. If the user enters this data:
95.019 123.45
the dialogue with the user looks like this:
Enter the lengths of the two sides.
95.019 123.45

The length of side A is 95.0190
The length of side B is 123.4500
The length of the hypotenuse is 155.7835

 
< previous page page_168 next page >