Guest User

Untitled

a guest
May 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int choice, x, y;
  6.  
  7. int fAddition(int a, int b) {
  8. int c = a + b;
  9. return(c);
  10. }
  11.  
  12. int fSubtraction(int a, int b) {
  13. int c = a - b;
  14. return(c);
  15. }
  16.  
  17. int fMultiplication(int a, int b) {
  18. int c = a * b;
  19. return(c);
  20. }
  21.  
  22. int fDivision(int a, int b) {
  23. if (b == 0) {
  24. return(42);
  25. }
  26.  
  27. else {
  28. int c = a / b;
  29. return(c);
  30. }
  31. }
  32.  
  33. int main() {
  34. int loop = 1;
  35. while (loop == 1) {
  36. cout << "\n Make a choice:" << endl;
  37. cout << " 1: Addition" << endl;
  38. cout << " 2: Subtraction" << endl;
  39. cout << " 3: Multiplication" << endl;
  40. cout << " 4: Division" << endl;
  41. cout << " 5: Quit" << endl;
  42. cout << " > ";
  43. cin >> choice;
  44. cout << endl;
  45. switch (choice) {
  46. case 1:
  47. cout << " Two numbers: ";
  48. cin >> x >> y;
  49. cout << " The result is: " << fAddition(x, y) << endl;
  50. break;
  51. case 2:
  52. cout << " Two numbers: ";
  53. cin >> x >> y;
  54. cout << " The result is: " << fSubtraction(x, y) << endl;
  55. break;
  56. case 3:
  57. cout << " Two numbers: ";
  58. cin >> x >> y;
  59. cout << " The result is: " << fMultiplication(x, y) << endl;
  60. break;
  61. case 4:
  62. cout << " Two numbers: ";
  63. cin >> x >> y;
  64. cout << " The result is: " << fDivision(x, y) << endl;
  65. break;
  66. case 5:
  67. loop = 0;
  68. break;
  69. default:
  70. cout << " That's not a valid option" << endl;
  71. }
  72. }
  73. return 0;
  74. }
Add Comment
Please, Sign In to add comment