Advertisement
Rondeo

Basic_Operations.cpp

Jun 27th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | Fixit | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. void menu();
  5. int add(int y, int z);
  6. int sub(int y, int z);
  7. int mult(int y, int z);
  8. float divide(float y, float z);
  9. int modulo(int y);
  10.  
  11. int main() {
  12.     int y, z, choice, sum, diff, prod, mod;
  13.     float quot;
  14.     char do_again;
  15.  
  16.     do {
  17.         menu();
  18.         cin >> choice;
  19.  
  20.         switch(choice) {
  21.             case 1:
  22.                 cout << "Addition\n";
  23.                 cout << "Enter y: ";
  24.                 cin >> y;
  25.                 cout << "Enter z: ";
  26.                 cin >> z;
  27.                 sum = add(y, z);
  28.                 cout << "Sum: " << sum << endl;
  29.                 break;
  30.  
  31.             case 2:
  32.                 cout << "Subtraction\n";
  33.                 cout << "Enter y: ";
  34.                 cin >> y;
  35.                 cout << "Enter z: ";
  36.                 cin >> z;
  37.                 diff = sub(y, z);
  38.                 cout << "Difference: " << diff << endl;
  39.                 break;
  40.  
  41.             case 3:
  42.                 cout << "Multiplication\n";
  43.                 cout << "Enter y: ";
  44.                 cin >> y;
  45.                 cout << "Enter z: ";
  46.                 cin >> z;
  47.                 prod = mult(y, z);
  48.                 cout << "Product: " << prod << endl;
  49.                 break;
  50.  
  51.             case 4:
  52.                 cout << "Division\n";
  53.                 cout << "Enter y: ";
  54.                 cin >> y;
  55.                 quot = divide(y, z);
  56.                 cout << "The quotient is: " << quot << endl;
  57.                 break;
  58.  
  59.             case 5:
  60.                 cout << "Modulo\n";
  61.                 cout << "Enter y: ";
  62.                 cin >> y;
  63.                 mod = modulo(y);
  64.                 cout << "The result is: " << mod << endl;
  65.                 break;
  66.  
  67.             case 6:
  68.                 cout << "Farewell to you, my friend!" << endl;
  69.                 break;
  70.  
  71.             default:
  72.                 cout << "Invalid Choice" << endl;
  73.                 return 0;
  74.         }
  75.  
  76.         cout << "Press [1] if you want another choice, [0] if you want to exit" << endl;
  77.         cin >> do_again;
  78.  
  79.         if (do_again == '1') {
  80.             system("CLS");
  81.             main();
  82.             return 0;
  83.         } else {
  84.             cout << "You choose to exit" << endl;
  85.             return 0;
  86.         }
  87.     } while (do_again != '0');
  88. }
  89.  
  90. void menu() {
  91.     cout << "[1] Add" << endl;
  92.     cout << "[2] Sub" << endl;
  93.     cout << "[3] Mult" << endl;
  94.     cout << "[4] Div" << endl;
  95.     cout << "[5] Modulo" << endl;
  96.     cout << "[6] Exit" << endl;
  97.     cout << "Enter your choice (1-6): ";
  98. }
  99.  
  100. int add(int a, int b) {
  101.     return a + b;
  102. }
  103.  
  104. int sub(int a, int b) {
  105.     return a - b;
  106. }
  107.  
  108. int mult(int a, int b) {
  109.     return a * b;
  110. }
  111.  
  112. float divide(float a, float b) {
  113.     return a / b;
  114. }
  115.  
  116. int modulo(int a) {
  117.     return a % 10;
  118. }
  119.  
Tags: ops
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement