/* Filename: grade2.cpp Author: Br. David Carlson Br. Isidore Minerd Date: January 4, 2000 Modified: June 26, 2000; August 19, 2001; This program asks the user to enter number grades between 0 and 100. It computes and prints the corresponding letter grade (A, B, C, D, or F) for each. The user is asked after each conversion whether or not to do another. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET Microsoft Visual Studio 2008 g++ under Linux */ #include using namespace std; // Function prototype: void DoOneGrade(void); int main(void) { char Reply; do { DoOneGrade(); cout << endl << "Do another (y/n)? "; cin >> Reply; cout << endl; } while ((Reply == 'Y') || (Reply == 'y')); return 0; } /* Given: Nothing. Task: To ask the user for a number grade and to print the corresponding letter grade. Return: Nothing. */ void DoOneGrade(void) { int Num; char Grade; cout << "Enter your number grade (integer from 0 to 100): "; cin >> Num; cin.get(); // Read in the newline at the end of that number! if ((Num < 0) || (Num > 100)) Grade = 'N'; else if (Num >= 90) Grade = 'A'; else if (Num >= 80) Grade = 'B'; else if (Num >= 70) Grade = 'C'; else if (Num >= 60) Grade = 'D'; else Grade = 'F'; cout << endl << "The letter grade is: " << Grade << endl; if (Grade == 'N') cout << "N stands for invalid. " << "You must use a number between 0 and 100." << endl; }