Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. string name;
  11. int selection;
  12. int x;
  13. int y;
  14. int correctAnswer;
  15. int userAnswer;
  16. int count = 1;
  17. int totalCorrectAnswers = 0;
  18. int numberOfAttempts = 0;
  19.  
  20.  
  21. cout << "Please enter your first name. ";
  22. cin >> name;
  23. cout << "\nHello, " << name << ". What sort of math problems would you like to work on?\n(Type the number, or type '4' to quit the program.)\n" << endl;
  24. cout << "1) Addition"
  25. << "\n2) Subtraction"
  26. << "\n3) Multiplication"
  27. << "\n4) Quit\n" << endl;
  28. cin >> selection;
  29. if (selection == 1)
  30. {
  31. cout << "\nAll right! Let's do some addition." << endl;
  32. cout << "When you've gotten 10 correct answers, you'll receive a grade out of 100.\n" << endl;
  33. while (totalCorrectAnswers < 10)
  34. {
  35. srand(time(NULL));
  36. x = rand() % 20;
  37. y = rand() % 20;
  38. correctAnswer = x + y;
  39. cout << "Question " << count << ": " << x << " + " << y << " = ";
  40. cin >> userAnswer;
  41. count++;
  42. numberOfAttempts++;
  43.  
  44.  
  45. if (userAnswer == correctAnswer)
  46. {
  47. cout << "Correct!\n";
  48. ++totalCorrectAnswers;
  49. }
  50. else
  51. {
  52. cout << "Incorrect.\n";
  53. }
  54.  
  55.  
  56. }
  57. cout << "Great job! Your total grade is " << ((totalCorrectAnswers / numberOfAttempts) * 100) << "." << endl;
  58. }
  59. else if (selection == 2)
  60. {
  61. cout << "All right! Let's do some subtraction." << endl;
  62. cout << "We're going to give you some basic subtraction problems, and when you've gotten 10 correct, you'll receive a grade out of 100." << endl;
  63. while (totalCorrectAnswers < 10)
  64. {
  65.  
  66. }
  67. }
  68. else if (selection == 3)
  69. {
  70. cout << "All right! Let's do some multiplication." << endl;
  71. cout << "We're going to give you some basic multiplication problems, and when you've gotten 10 correct, you'll receive a grade out of 100." << endl;
  72. while (totalCorrectAnswers < 10)
  73. {
  74.  
  75. }
  76. }
  77. else if (selection == 4)
  78. {
  79. cout << "Goodbye." << endl;
  80. }
  81. else
  82. {
  83. cout << "Error! Please enter 1, 2, 3, or 4.\n";
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement