// // Filename: pgm2_3d.cpp // // Description: Demonstration of a while statement to collect a sequence // of input data from the user. With valid data checking. // Use of nested while loops is demonstrated. The user // decides when no more data is available. // // ENSC 104: Digital Computer Programming // // Instructor: Dr. Walsh // // Section: 2 // // Date Created: 01/29/98 // Last Modified: 02/14/98 // // Name: N/A // #include main() { int score; int total = 0; int count = 0; cout << "Enter an exam score(-1 to END): "; cin >> score; while( score != -1 ) { while ( score < 0 || score > 100 ) { cout << "***** INVALID EXAM SCORE *****" << endl; cout << "Enter an exam score: "; cin >> score; } total = total + score; count = count + 1; cout << "Enter an exam score(-1 to END): "; cin >> score; } if ( count > 0 ) { cout << "The average score is " << total/count << endl; cout << "\n\nYou entered " << count << " scores\n"; } else { cout << "\nNo scores were entered!!\n"; } return 0; }