Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. void chapter210quiz()
  2. {
  3.  
  4. std::cout << "Pick a question's solution:\n" << "[1]: Question 3, double calculator\n" << "[2]: Question 4, gravity simulator\n\n";
  5. int quizChoice{ 0 };
  6. std::cin >> quizChoice;
  7.  
  8. if (quizChoice == 1)
  9. {
  10. for (;;) // alternative to while(true)
  11. {
  12.  
  13. double result{ 0 };
  14.  
  15. std::cout << "Enter a double value:\n";
  16. double userInput1{ 0 };
  17. std::cin >> userInput1;
  18.  
  19. std::cout << "Enter a double value:\n";
  20. double userInput2{ 0 };
  21. std::cin >> userInput2;
  22.  
  23. std::cout << "Enter operator:\n" << "+, -, * or /\n";
  24. char userOperator{ 0 };
  25. std::cin >> userOperator;
  26.  
  27. if (userOperator == '+')
  28. {
  29. result = userInput1 + userInput2;
  30. std::cout << result << std::endl;
  31. }
  32.  
  33. else if (userOperator == '-')
  34. {
  35. result = userInput1 + userInput2;
  36. std::cout << result << std::endl;
  37. }
  38.  
  39. else if (userOperator == '*')
  40. {
  41. result = userInput1 * userInput2;
  42. std::cout << result << std::endl;
  43. }
  44.  
  45. else if (userOperator == '/')
  46. {
  47. result = userInput1 / userInput2;
  48. std::cout << result << std::endl;
  49. }
  50.  
  51. else
  52. {
  53. std::cout << "False input" << std::endl;
  54. }
  55.  
  56. std::cout << "\nContinue?\n\n" << "[1]: Continue\n" << "[2]: Cancel\n";
  57. std::cin >> quizChoice;
  58.  
  59. if (quizChoice == 2)
  60. {
  61. break;
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement