初学者的C++练习题——(一)计分程序

Grading Program

Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)

Write a program that allows the user to enter the grade scored in a programming class (0-100).
If the user scored a 100 then notify the user that they got a perfect score.
#include using namespace std; int main() { cout << "Enter the grade scored in your programming class (1-100): "; int grade; cin >> grade; if (grade == 100) { cout << "You got a perfect score!" << endl; } system("pause"); }
★ Modify the program so that if the user scored a 90-100 it informs the user that they scored an A
#include using namespace std; int main() { cout << "Enter the grade scored in your programming class (1-100): "; int grade; cin >> grade; if (grade == 100) { cout << "You got a perfect score!" << endl; } if (grade >=90 && grade <=100) { cout << "You scored an A." << endl; } system("pause"); }
★★ Modify the program so that it will notify the user of their letter grade
0-59 F 60-69 D 70-79 C 80-89 B 90-100 A

 

#include using namespace std; int main() { cout << "Enter the grade scored in your programming class (1-100): "; int grade; cin >> grade; switch ( grade/10 ) { case 10: cout << "You got a perfect score!" << endl; case 9: cout << "You scored an A." << endl; break; case 8: cout << "You scored a B." << endl; break; case 7: cout << "You scored a C." << endl; break; case 6: cout << "You scored a D." << endl; break; case 5: cout << "You scored an F." << endl; break; default:; } system("pause"); }

你可能感兴趣的:(c++,user,class,system,variables,types,C/C++)