fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctype.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. cout << "\t\tThis Program tests your Math abilities\n";
  9. cout << "\tfor addition / subtraction / multiplication / division / modulo\n";
  10. cout << "\t\t\tBy Hanjun Park\n";
  11. cout << "\n";
  12. cout << "\n";
  13. cout << "\t*** IMPORTANT NOTE : \n";
  14. cout << "\t\tFor division please provide the answer\n";
  15. cout << "\tto two decimal places ONLY ***\n";
  16. cout << "\n";
  17.  
  18. double choice;
  19. float firstNumAdd, secondNumAdd, resultAdd;
  20. float firstNumSub, secondNumSub, resultSub;
  21. float firstNumMul, secondNumMul, resultMul;
  22. float firstNumDiv, secondNumDiv, resultDiv;
  23. int firstNumMol, secondNumMol, resultMol;
  24.  
  25. const int ADDITION = 1,
  26. SUBTRACTION = 2,
  27. MULTIPLICATION = 3,
  28. DIVISION = 4,
  29. MODULO = 5,
  30. END_PROGRAM = 6;
  31.  
  32.  
  33. cout << "\n";
  34. cout << "\t1] Addition\n";
  35. cout << "\t2] Subtraction\n";
  36. cout << "\t3] Multiplication\n";
  37. cout << "\t4] Division\n";
  38. cout << "\t5] Modulo\n";
  39. cout << "\t6] End program\n";
  40. cout << "\n";
  41.  
  42.  
  43.  
  44. cout << "\tEnter Choice: ";
  45. cin >> choice;
  46. cout << choice << "\n";
  47. if ((float)choice / 1.00 != int(choice))
  48. {
  49. cout << "\tInput was not a WHOLE number\n" << "\tGoodbye! ... Exiting the program\n" << endl << "Please Hit EXTER to Exit ...";
  50. cin.get();
  51. cin.get();
  52. return 0;
  53. }
  54. else if (choice >= 1 && choice <= 6)
  55. {
  56. cout << choice;
  57. switch ((int)choice)
  58. {
  59. case ADDITION: cout << "\tEnter First Number: ";
  60. cin >> firstNumAdd;
  61. cout << "\n";
  62. cout << "\tEnter Second Number: ";
  63. cin >> secondNumAdd;
  64. cout << "\n";
  65. resultAdd = firstNumAdd + secondNumAdd;
  66. cout << "\t" << firstNumAdd << " + " << secondNumAdd << " = " << resultAdd << endl;
  67. cout << "\n";
  68. cout << "\n";
  69. cout << "\tPlease Hit ENTER to Exit ...";
  70. break;
  71.  
  72. case SUBTRACTION: cout << "\tEnter First Number: ";
  73. cin >> firstNumSub;
  74. cout << "\n";
  75. cout << "\tEnter Second Number: ";
  76. cin >> secondNumSub;
  77. cout << "\n";
  78. resultSub = firstNumSub - secondNumSub;
  79. cout << "\t" << firstNumSub << " - " << secondNumSub << " = " << resultSub << endl;
  80. cout << "\n";
  81. cout << "\n";
  82. cout << "\tPlease Hit ENTER to Exit ...";
  83. break;
  84.  
  85. case MULTIPLICATION: cout << "\tEnter First Number: ";
  86. cin >> firstNumMul;
  87. cout << "\n";
  88. cout << "\tEnter Second Number: ";
  89. cin >> secondNumMul;
  90. cout << "\n";
  91. resultMul = firstNumMul * secondNumMul;
  92. cout << "\t" << firstNumMul << " * " << secondNumMul << " = " << resultMul << endl;
  93. cout << "\n";
  94. cout << "\n";
  95. cout << "\tPlease Hit ENTER to Exit ...";
  96. break;
  97.  
  98.  
  99. case DIVISION: cout << "\tEnter First Number: ";
  100. cin >> firstNumDiv;
  101. cout << "\n";
  102. cout << "\tEnter Second Number: ";
  103. cin >> secondNumDiv;
  104. cout << "\n";
  105. resultDiv = firstNumDiv / secondNumDiv;
  106. cout << "\t" << firstNumDiv << " / " << secondNumDiv;
  107. cout << setprecision(2) << fixed;
  108. cout << " = " << resultDiv << endl;
  109. cout << "\n";
  110. cout << "\n";
  111. cout << "\tPlease Hit ENTER to Exit ...";
  112. break;
  113.  
  114.  
  115. case MODULO: cout << "\tEnter First Number: ";
  116. cin >> firstNumMol;
  117. cout << "\n";
  118. cout << "\tEnter Second Number: ";
  119. cin >> secondNumMol;
  120. cout << "\n";
  121. resultMol = firstNumMol % secondNumMol;
  122. cout << "\t" << firstNumMol << " % " << secondNumMol << " = " << resultMol << endl;
  123. cout << "\n";
  124. cout << "\n";
  125. cout << "\tPlease Hit ENTER to Exit ...";
  126. break;
  127.  
  128. case END_PROGRAM: cout << "\n";
  129. cout << "\tGoodbye! ...Exiting the program" << endl << endl;
  130. cout << "\tPlease Hit ENTER to Exit ...";
  131. break;
  132.  
  133. }
  134. }
  135. else if ((choice < 1 || choice > 6) && isdigit(choice))
  136. {
  137. cout << isalpha(choice);
  138. cout << isdigit(choice);
  139. cout << "\tInput is out of range. Valid range is 1-6\n" << "\tGoodbye! ...Exiting the program" << endl << endl << "\tPlease Hit ENTER to Exit ...";
  140. cin.get();
  141. cin.get();
  142. return 0;
  143. }
  144. else
  145. {
  146. cout << choice;
  147. cout << isalpha(choice);
  148. cout << isdigit(choice);
  149. cout << "\tInput is not a number\n" << "\tGoodbye! ...Exiting the program" << endl << endl << "\tPlease Hit ENTER to EXIT ...";
  150. cin.get();
  151. cin.get();
  152. return 0;
  153. }
  154. cin.get();
  155. cin.get();
  156. return 0;
  157. }
Success #stdin #stdout 0s 16064KB
stdin
4.4
stdout
		This Program tests your Math abilities
	for addition / subtraction / multiplication / division / modulo
			By Hanjun Park


	***   IMPORTANT NOTE  : 
		For division please provide the answer
	to two decimal places ONLY  ***


	1]  Addition
	2]  Subtraction
	3]  Multiplication
	4]  Division
	5]  Modulo
	6] End program

	Enter Choice: 4.4
	Input was not a WHOLE number
	Goodbye! ... Exiting the program

Please Hit EXTER to Exit ...