Advertisement
JamesDamico

BCS 120 - Assignment 3

Nov 13th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. //Assignment 3
  2. int addNumbers(int x, int y)
  3. {
  4. return x + y;
  5. }
  6.  
  7. //Assignment 3
  8. int subtractNumbers(int x, int y)
  9. {
  10. return x - y;
  11. }
  12.  
  13. //Assignment 3
  14. int multiplyNumbers(int x, int y)
  15. {
  16. return x * y;
  17. }
  18.  
  19. //Assignment 3
  20. int divideNumbers(int x, int y)
  21. {
  22. return x / y;
  23. }
  24.  
  25. //Assignment 3
  26. void calculator(string operation)
  27. {
  28. system("cls");
  29. int x,
  30. y,
  31. result;
  32.  
  33. cout << "Enter the first number:";
  34. cin >> x;
  35.  
  36. cout << "Enter the second number:";
  37. cin >> y;
  38.  
  39. if (operation == "+")
  40. {
  41. result = addNumbers(x, y);
  42. }
  43. else if (operation == "-")
  44. {
  45. result = subtractNumbers(x, y);
  46. }
  47. else if (operation == "x")
  48. {
  49. result = multiplyNumbers(x, y);
  50. }
  51. else if (operation == "/")
  52. {
  53. result = divideNumbers(x, y);
  54. }
  55.  
  56. cout << x << operation << y << "=" << result << endl;
  57. system("pause");
  58. }
  59.  
  60. //Assignment 3
  61. void showMenu()
  62. {
  63.  
  64. char selection;
  65. system("cls");
  66.  
  67. do
  68. {
  69. cout << " Calculator Menu\n";
  70. cout << " ====================================\n";
  71. cout << " 1. Add\n";
  72. cout << " 2. Subtract\n";
  73. cout << " 3. Multiple\n";
  74. cout << " 4. Divide";
  75. cout << "\n";
  76. cout << " X. Exit\n";
  77. cout << " ====================================\n";
  78. cout << " Enter your selection: ";
  79. cin >> selection;
  80. cout << endl;
  81.  
  82. switch (selection)
  83. {
  84. case '1':
  85. calculator("+");
  86. system("cls");
  87. break;
  88. case '2':
  89. calculator("-");
  90. system("cls");
  91. break;
  92. case '3':
  93. calculator("x");
  94. system("cls");
  95. break;
  96. case '4':
  97. calculator("/");
  98. system("cls");
  99. break;
  100.  
  101. case 'x':
  102. case 'X':
  103. _getch();
  104. return;
  105. default: cout << selection << " is not a valid menu item.\n";
  106.  
  107. cout << endl;
  108. }
  109. } while (selection != 'x' || selection != 'X');
  110. }
  111.  
  112. //Assignment 3
  113. void assignment3()
  114. {
  115. showMenu();
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement