Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7.  
  8. {
  9. int option;
  10. int score = 105;
  11. double gpa;
  12. do {
  13. cout << "Menu:\n"
  14. << "1. Enter your testscore \n"
  15. << "2. Enter your GPA to see if you made the deans list \n"
  16. << "3. Exit\n"
  17. << "Enter an option by entering 1, 2, or 3: ";
  18.  
  19. cin >> option;
  20. cout << endl;
  21.  
  22.  
  23. switch (option)
  24. {
  25. case 1:
  26. cout << " You chose option one" << endl;
  27. cout << "Enter your test score" << endl;
  28. cin >> score;
  29. while (cin.fail()) // check for input error
  30. {
  31. if (cin.eof())
  32. {
  33. // Once EOF file has been reached with cin,
  34. // you can't do much. Figure out a way to bail
  35. // from the loop.
  36. }
  37.  
  38. cin.clear();
  39.  
  40. // Also, ignore not just one character but till the end of the line.
  41. // cin.ignore();
  42. cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  43.  
  44. cout << "You entered an incorrect value. Please enter an integer 0-100" << endl;
  45. cin >> score;
  46. }
  47.  
  48. if (score >= 90 && score <= 100) {
  49. cout << "The grade is an A" << endl;
  50. }
  51. else if (score >= 80 && score < 90) {
  52. cout << "The grade is a B" << endl;
  53. }
  54. else if (score >= 70 && score < 80) {
  55. cout << "The grade is a c" << endl;
  56. }
  57. else if (score >= 60 && score < 70) {
  58. cout << "The grade is a D" << endl;
  59. }
  60. else if (score >= 0 && score < 60) {
  61. cout << "The grade is a F" << endl;
  62. }
  63.  
  64. else {
  65. cout << "Your score is out of range" << endl;
  66. }
  67. break;
  68.  
  69. case 2:
  70. cout << "You chose option two\n";
  71. cout << "Enter your GPA" << endl;
  72. cin >> gpa;
  73. while (cin.fail()) // check for input error
  74. {
  75. if (cin.eof())
  76. {
  77. // Once EOF file has been reached with cin,
  78. // you can't do much. Figure out a way to bail
  79. // from the loop.
  80. }
  81.  
  82. cin.clear();
  83.  
  84. // Also, ignore not just one character but till the end of the line.
  85. // cin.ignore();
  86. cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  87.  
  88. cout << "You entered an incorrect value. Please enter a value between 0-4" << endl;
  89. cin >> gpa;
  90. }
  91. if (gpa >= 3.9 && gpa <= 4.0) {
  92.  
  93. cout << "You're on the deans list." << endl;
  94. }
  95. else if (gpa >= 0 && gpa < 3.8) {
  96. cout << "You're not elligible for the deans list." << endl;
  97. }
  98. else {
  99. cout << "Your gpa is out of range" << endl;
  100. }
  101. break;
  102.  
  103. case 3:
  104. cout << "You chose to exit, thank you.\n";
  105. break;
  106.  
  107. default:
  108. cout << "Invalid option, please enter 1, 2, or 3.\n";
  109. }
  110.  
  111.  
  112. }
  113.  
  114. while (option != 3);
  115.  
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement