Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void menu();
- int add(int y, int z);
- int sub(int y, int z);
- int mult(int y, int z);
- float divide(float y, float z);
- int modulo(int y);
- int main() {
- int y, z, choice, sum, diff, prod, mod;
- float quot;
- char do_again;
- do {
- menu();
- cin >> choice;
- switch(choice) {
- case 1:
- cout << "Addition\n";
- cout << "Enter y: ";
- cin >> y;
- cout << "Enter z: ";
- cin >> z;
- sum = add(y, z);
- cout << "Sum: " << sum << endl;
- break;
- case 2:
- cout << "Subtraction\n";
- cout << "Enter y: ";
- cin >> y;
- cout << "Enter z: ";
- cin >> z;
- diff = sub(y, z);
- cout << "Difference: " << diff << endl;
- break;
- case 3:
- cout << "Multiplication\n";
- cout << "Enter y: ";
- cin >> y;
- cout << "Enter z: ";
- cin >> z;
- prod = mult(y, z);
- cout << "Product: " << prod << endl;
- break;
- case 4:
- cout << "Division\n";
- cout << "Enter y: ";
- cin >> y;
- quot = divide(y, z);
- cout << "The quotient is: " << quot << endl;
- break;
- case 5:
- cout << "Modulo\n";
- cout << "Enter y: ";
- cin >> y;
- mod = modulo(y);
- cout << "The result is: " << mod << endl;
- break;
- case 6:
- cout << "Farewell to you, my friend!" << endl;
- break;
- default:
- cout << "Invalid Choice" << endl;
- return 0;
- }
- cout << "Press [1] if you want another choice, [0] if you want to exit" << endl;
- cin >> do_again;
- if (do_again == '1') {
- system("CLS");
- main();
- return 0;
- } else {
- cout << "You choose to exit" << endl;
- return 0;
- }
- } while (do_again != '0');
- }
- void menu() {
- cout << "[1] Add" << endl;
- cout << "[2] Sub" << endl;
- cout << "[3] Mult" << endl;
- cout << "[4] Div" << endl;
- cout << "[5] Modulo" << endl;
- cout << "[6] Exit" << endl;
- cout << "Enter your choice (1-6): ";
- }
- int add(int a, int b) {
- return a + b;
- }
- int sub(int a, int b) {
- return a - b;
- }
- int mult(int a, int b) {
- return a * b;
- }
- float divide(float a, float b) {
- return a / b;
- }
- int modulo(int a) {
- return a % 10;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement