// Chris Alvin // CS110 // Program 1 // The program simulates a simple grading program. // Limitations: integer input expected. #include #include int main() { cout << setiosflags (ios::showpoint | ios::fixed) << setprecision(2); int choice = 1; // user-input menu int num = 0; // input number int high = -1, low = 101; // init to values out of range unsigned int count = 0; unsigned int total = 0; // 6 is the only value that will quit; all other ints acceptable while (choice != 6) { // Print the menu cout << "Please select the operation which you would like to perform?" << endl; cout << "1) Enter scores." << endl; cout << "2) Query the current average." << endl; cout << "3) Query the current high score." << endl; cout << "4) Query the current low score." << endl; cout << "5) Clear all data." << endl; cout << "6) Exit." << endl; cin >> choice; // switch on menu user input switch (choice) { case 1: cout << "Enter first score." << endl; cin >> num; while (num >= 0 && num <= 100) { if (high < num) high = num; if (low > num) low = num; count++; total += num; cout << "Enter another score (negative number to stop)." << endl; cin >> num; } break; case 2: cout << "The current average is "; if (count == 0) cout << 0 << endl; else if (total % count == 0) cout << total / count << endl; else cout << (float)(total) / count << endl; break; case 3: cout << "The current high score is "; if (high == -1) cout << "UNKNOWN" << endl; else cout << high << endl; break; case 4: cout << "The current low score is "; if (low == 101) cout << "UNKNOWN" << endl; else cout << low << endl; break; case 5: high = -1; low = 101; count = 0; total = 0; cout << "Data cleared." << endl; break; case 6: break; default: cout << "ERROR: invalid entry." << endl; } cout << endl; } return 0; }