1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
int addition(int x, int y);
#include <conio.h>
#include <iostream>
#pragma hdrstop
using namespace std;
int addition (int, int);
void showResult(int);
int addition(int x, int y) {
return x + y; //change to + - * or /.
}
int subtract(int x, int y) {
return x - y; //change to + - * or /.
}
int multiplication(int x, int y) {
return x * y; //change to + - * or /.
}
int dividation(int x, int y) {
return x / y; //change to + - * or /.
}
void showResult(int res) {
cout<<"The result is "<< res << endl;
}
int main(int argc, char **argv, int res) {
int x, y, result;
char calcer;
cout << endl <<"Enter the first value:";
cin >> x;
cout << endl <<"Enter your calctype\n + for Addition, - for Subtraction\n* fpr multiplication and / for division:";
cin >> calcer;
cout <<"Enter the second value: ";
cin >> y;
if (calcer == '+') {
result = addition(x, y);
showResult(result);
} else if (calcer == '-') {
result = subtract(x, y);
showResult(result);
} else if (calcer == '*') {
result = multiplication(x, y);
showResult(result);
} else if (calcer == '/') {
result = dividation(x, y);
showResult(result);
} else {
cout<<"Incorrect calculation type selected. Please restart the program.\n";
}
cout << endl << endl << "Press any key to continue...";
getch();
return 0;
}
|