# Answer to Question #35447 in C++ for Hammoud

Question #35447
Write a program that mimics a calculator. The program should take as inputs two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For division, if the denominator is zero, output an appropriate message.) Some sample outputs follow: 3 + 4 = 7 13 * 5 = 65 10 – 5 = 5 30 / 0 = Error: Division-by-Zero! 14 & 7 = Error: Invalid Operation!
#include<iostream>
using namespace std;

int main() {
int var1, var2;
char operation;

cout << "Enter the first number : ";
cin >> var1;
cout << endl;

cout <<"Enter the operation to be perfomed : ";
cin >> operation;
cout << endl;

cout << "Enter the second nuber : ";
cin >> var2;
cout << endl;

bool right_input = false;
if (operation == '+') {
cout << var1 << " " << operation << " " << var2 << " = " << (var1 + var2);
right_input = true;
}
if (operation == '-') {
cout << var1 << " " << operation << " " << var2 << " = " << (var1 - var2);
right_input = true;
}
if (operation == '*') {
cout << var1 << " " << operation << " " << var2 << " = " << (var1 * var2);
right_input = true;
}
if (operation == '/' && var2 != 0) {
cout << var1 << " " << operation << " " << var2 << " = " << (var1 - var2);
right_input = true;
}
if (operation == '/' && var2 == 0) {
cout << "Error. Division by zero.";
right_input = true;
}
if (!right_input) {
cout << var1 << " " << operation << " " << var2 << " = " << "Error;";
cout << "Invalid Operation!";
}

cout << endl;

system("pause");

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!