Advertisement
jerimin

practice code

Oct 9th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. // This program displays a list of operations and allows an elementary student pick from te list. For the selected operation, the program generates Random Numbers.
  2.  
  3. #include <iostream>
  4. using namespace std;
  5. #include <cstdlib>
  6. #include <ctime>
  7.  
  8. int main()
  9. {
  10. //Instruction Display, Declaration and Input.
  11.  
  12. cout << "Find Below instructions regarding operations to be performed. Please Choose from this List. " << endl;
  13. cout << "Choose 1 for Addition." << endl;
  14. cout << "Choose 2 for Subtraction." << endl;
  15. cout << "Choose 3 for Multiplication." << endl;
  16. cout << "Choose 4 for Division" << endl;
  17.  
  18. int choice;
  19.  
  20. enum Selected_Choice {Subtraction=1, Division} selected_choice;
  21.  
  22. cout << "Enter your choice : ";
  23. cin >> choice;
  24.  
  25. //Variable Declaration
  26. int number1, number2, number3, subtraction, answer;
  27. double division;
  28.  
  29. // Generating Two Random numbers
  30. srand(time(0));
  31. number1 = 1+ rand() % 10;
  32. number2 = 1+ rand() % 10;
  33.  
  34. // Code
  35. switch (choice)
  36. {
  37. case Subtraction:
  38. // to avoid negative
  39.  
  40. if (number1 < number2)
  41. {
  42. int temp = number1;
  43. number1 = number2;
  44. number2 = temp;
  45. }// Swaping
  46.  
  47. cout << number1 << " - " << number2 << " = " " ? " << endl;
  48. cout << " Enter your Answer : ";
  49. cin >> answer;
  50. subtraction = number1 - number2;
  51.  
  52. if (answer == subtraction)
  53. cout << " Correct Answer; Good Job ! " << endl;
  54. else
  55. cout << " Wrong Answer. The correct answer is " << subtraction << endl;
  56.  
  57. break;
  58.  
  59. case Division :
  60. cout << number1 << " divided by " << number2 << " is ? " << endl;
  61. cout << "Enter your Answer : ";
  62. cin >> answer;
  63.  
  64. division = number1 /  ststic_cast <double> (number2); //missing cast
  65.  
  66. if (answer == division)
  67. cout << " Correct Answer; Good Job ! " << endl;
  68. else
  69. cout << " Wrong Answer. The correct answer is " << division << endl;
  70.  
  71. break;
  72.  
  73. default :
  74. cout << " You have chosen a wrong Command!! " << endl;
  75.  
  76. } // Switch Cases
  77.  
  78. cout << " Thank you for taking this test." << endl;
  79.  
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement