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
|
#include <iostream>
int Calculator(int&, int&);
int Addition(int, int);
int Subtraction(int, int);
int Multiplication(int, int);
int Division(int, int);
int main() {
int v1 {}, v2 {}, result {};
int S {Calculator(v1, v2)};
if (S == '+')
result = Addition(v1, v2);
else if (S == '-')
result = Subtraction(v1, v2);
else if (S == 'x')
result = Multiplication(v1, v2);
else
result = Division(v1, v2);
std::cout << "Result is " << result << '\n';
}
int Addition(int n1, int n2) { return n1 + n2; }
int Subtraction(int n1, int n2) { return n1 - n2; }
int Multiplication(int n1, int n2) { return n1 * n2; }
int Division(int n1, int n2) { return n1 / n2; }
int Calculator(int& Num1, int& Num2) {
char Operation {};
std::cout << "Welcome!\n";
std::cout << "Please enter First Number here: ";
std::cin >> Num1;
std::cout << "Please Enter Second Number here: ";
std::cin >> Num2;
std::cout << "\nPlease select the operation from the following:\n";
std::cout << "(Addition = +; Subtraction = -; Multiplication = x; Division = /)\n";
do {
std::cout << "Enter here: ";
std::cin >> Operation;
} while (Operation != '+' && Operation != '-' && Operation != 'x' && Operation != '/' &&
(std::cout << "Invalid Input. Please try again.\n"));
return Operation;
}
|