< previous page page_223 next page >

Page 223
typedef int Boolean;
const Boolean TRUE = 1;
const Boolean FALSE = 0;

int main()
{
    float   average;      // Average of three test scores
    long    studentID;    // Student's identification number
    int     test1;        // Score for first test
    int     test2;        // Score for second test
    int     test3;        // Score for third test
    Boolean dataOK;       // TRUE if data is correct
    cout.setf(ios::fixed, ios::floatfield);  // Set up floating pt.
    cout.setf(ios::showpoint);                //   output format

    // Get data

    cout << Enter a Student ID number and three test scores:
         < endl;
    cin >> studentID >> test1 >> test2 >> test3;
    cout << Student number:  < studentID <   Test Scores:
         < test1 < ,  < test2 < ,  < test3 < endl;

    // Test data

    if (test1 < 0 || test2 < 0 || test3 < 0)
        dataOK = FALSE;
    else
        dataOK = TRUE;

    if (dataOK)
{
        // Calculate average

        average = float(test1 + test2 + test3) / 3.0;

        // Print message

        cout << Average score is 
             < setprecision(2) < average < --;
        if (average >= 60.0)

 
< previous page page_223 next page >