Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int choice, x, y;
- int fAddition(int a, int b) {
- int c = a + b;
- return(c);
- }
- int fSubtraction(int a, int b) {
- int c = a - b;
- return(c);
- }
- int fMultiplication(int a, int b) {
- int c = a * b;
- return(c);
- }
- int fDivision(int a, int b) {
- if (b == 0) {
- return(42);
- }
- else {
- int c = a / b;
- return(c);
- }
- }
- int main() {
- int loop = 1;
- while (loop == 1) {
- cout << "\n Make a choice:" << endl;
- cout << " 1: Addition" << endl;
- cout << " 2: Subtraction" << endl;
- cout << " 3: Multiplication" << endl;
- cout << " 4: Division" << endl;
- cout << " 5: Quit" << endl;
- cout << " > ";
- cin >> choice;
- cout << endl;
- switch (choice) {
- case 1:
- cout << " Two numbers: ";
- cin >> x >> y;
- cout << " The result is: " << fAddition(x, y) << endl;
- break;
- case 2:
- cout << " Two numbers: ";
- cin >> x >> y;
- cout << " The result is: " << fSubtraction(x, y) << endl;
- break;
- case 3:
- cout << " Two numbers: ";
- cin >> x >> y;
- cout << " The result is: " << fMultiplication(x, y) << endl;
- break;
- case 4:
- cout << " Two numbers: ";
- cin >> x >> y;
- cout << " The result is: " << fDivision(x, y) << endl;
- break;
- case 5:
- loop = 0;
- break;
- default:
- cout << " That's not a valid option" << endl;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment