Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Assignment 3
- int addNumbers(int x, int y)
- {
- return x + y;
- }
- //Assignment 3
- int subtractNumbers(int x, int y)
- {
- return x - y;
- }
- //Assignment 3
- int multiplyNumbers(int x, int y)
- {
- return x * y;
- }
- //Assignment 3
- int divideNumbers(int x, int y)
- {
- return x / y;
- }
- //Assignment 3
- void calculator(string operation)
- {
- system("cls");
- int x,
- y,
- result;
- cout << "Enter the first number:";
- cin >> x;
- cout << "Enter the second number:";
- cin >> y;
- if (operation == "+")
- {
- result = addNumbers(x, y);
- }
- else if (operation == "-")
- {
- result = subtractNumbers(x, y);
- }
- else if (operation == "x")
- {
- result = multiplyNumbers(x, y);
- }
- else if (operation == "/")
- {
- result = divideNumbers(x, y);
- }
- cout << x << operation << y << "=" << result << endl;
- system("pause");
- }
- //Assignment 3
- void showMenu()
- {
- char selection;
- system("cls");
- do
- {
- cout << " Calculator Menu\n";
- cout << " ====================================\n";
- cout << " 1. Add\n";
- cout << " 2. Subtract\n";
- cout << " 3. Multiple\n";
- cout << " 4. Divide";
- cout << "\n";
- cout << " X. Exit\n";
- cout << " ====================================\n";
- cout << " Enter your selection: ";
- cin >> selection;
- cout << endl;
- switch (selection)
- {
- case '1':
- calculator("+");
- system("cls");
- break;
- case '2':
- calculator("-");
- system("cls");
- break;
- case '3':
- calculator("x");
- system("cls");
- break;
- case '4':
- calculator("/");
- system("cls");
- break;
- case 'x':
- case 'X':
- _getch();
- return;
- default: cout << selection << " is not a valid menu item.\n";
- cout << endl;
- }
- } while (selection != 'x' || selection != 'X');
- }
- //Assignment 3
- void assignment3()
- {
- showMenu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement