Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. void error()
  5. {
  6. using namespace std;
  7. cout << "An error has occurred... Program exiting..." << endl;
  8. system("pause");
  9. }
  10. int main()
  11. {
  12. using namespace std;
  13.  
  14. //Declaring doubles and string
  15. double correct; //points correct
  16. double possible; //points possible
  17. double result; //result of correct divided by possible
  18. string input = ""; //user input
  19.  
  20. //Getting student's amount of points correct
  21. cout << "Enter amount student got correct: ";
  22. cin >> correct;
  23. cout << endl;
  24.  
  25. //Getting total points possible
  26. cout << "Enter amount of points possible: ";
  27. cin >> possible;
  28. cout << endl;
  29.  
  30. //Calculating percentage
  31. result = correct / possible;
  32. result = result * 100; //split result into 2 so the order of operations didn't get messed up
  33. cout << "Percentage: " << result << "%" << endl;
  34.  
  35. //Calculating grade
  36. cout << "Grade: ";
  37. if (result == 100){
  38. cout << "5" << endl;
  39. }else if (result < 100 && result >= 80){
  40. cout << "4" << endl;
  41. }else if (result < 79 && result >= 69){
  42. cout << "3" << endl;
  43. }else if (result < 68 && result >= 55){
  44. cout << "2" << endl;
  45. }else if (result < 54 && result >= 0){
  46. cout << "1" << endl;
  47.  
  48. }
  49.  
  50. //Asking user if they would like to exit or not
  51. cout << endl << "Would you like to exit, or grade another student?\n";
  52. cout << "To exit, type \"exit\"" << endl;
  53. cout << "To grade another student, type \"new\"" << endl;
  54. cout << endl;
  55. cin >> input;
  56. if (input=="exit"){ //if user typed exit, then exit
  57. exit(0); //exit returning 0 meaning program didn't encounter errors
  58. }else if (input=="new"){ //if user typed new, then go back to the start of main
  59. system("cls"); //clear the window
  60. main(); //go back to the beginning
  61. }else{
  62. error();//error
  63. }
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement