Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int option;
- int score = 105;
- double gpa;
- do {
- cout << "Menu:\n"
- << "1. Enter your testscore \n"
- << "2. Enter your GPA to see if you made the deans list \n"
- << "3. Exit\n"
- << "Enter an option by entering 1, 2, or 3: ";
- cin >> option;
- cout << endl;
- switch (option)
- {
- case 1:
- cout << " You chose option one" << endl;
- cout << "Enter your test score" << endl;
- cin >> score;
- while (cin.fail()) // check for input error
- {
- if (cin.eof())
- {
- // Once EOF file has been reached with cin,
- // you can't do much. Figure out a way to bail
- // from the loop.
- }
- cin.clear();
- // Also, ignore not just one character but till the end of the line.
- // cin.ignore();
- cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- cout << "You entered an incorrect value. Please enter an integer 0-100" << endl;
- cin >> score;
- }
- if (score >= 90 && score <= 100) {
- cout << "The grade is an A" << endl;
- }
- else if (score >= 80 && score < 90) {
- cout << "The grade is a B" << endl;
- }
- else if (score >= 70 && score < 80) {
- cout << "The grade is a c" << endl;
- }
- else if (score >= 60 && score < 70) {
- cout << "The grade is a D" << endl;
- }
- else if (score >= 0 && score < 60) {
- cout << "The grade is a F" << endl;
- }
- else {
- cout << "Your score is out of range" << endl;
- }
- break;
- case 2:
- cout << "You chose option two\n";
- cout << "Enter your GPA" << endl;
- cin >> gpa;
- while (cin.fail()) // check for input error
- {
- if (cin.eof())
- {
- // Once EOF file has been reached with cin,
- // you can't do much. Figure out a way to bail
- // from the loop.
- }
- cin.clear();
- // Also, ignore not just one character but till the end of the line.
- // cin.ignore();
- cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- cout << "You entered an incorrect value. Please enter a value between 0-4" << endl;
- cin >> gpa;
- }
- if (gpa >= 3.9 && gpa <= 4.0) {
- cout << "You're on the deans list." << endl;
- }
- else if (gpa >= 0 && gpa < 3.8) {
- cout << "You're not elligible for the deans list." << endl;
- }
- else {
- cout << "Your gpa is out of range" << endl;
- }
- break;
- case 3:
- cout << "You chose to exit, thank you.\n";
- break;
- default:
- cout << "Invalid option, please enter 1, 2, or 3.\n";
- }
- }
- while (option != 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement