Write a program that has the user enter two integers and then has the user enter a math operand to do the mathematic operation on the two inputted integers. The operands are ‘+’, ‘-‘, ‘*’, ‘/’, and ‘%’, any other character entered for the math operand should produce an error message of some kind. If the operand is correct, then the mathematical output should be displayed along with the correct formula. For example, if 4 and 6 and + are entered, output should be something like the following: 4 + 6 = 10. To receive full credit you must use a “switch” statement in your program. Program should also continue to loop until the user chooses ‘N’ for No in some kind of loop.
Here is my program
#include<iostream>
using namespace std;
int main()
{
int IntegerOne, IntegerTwo, Answer,Operand;
cout << "Enter equation to be performed --> ";
cin >> IntegerOne,IntegerTwo,Operand;
if (Operand =='+')
{
Answer=IntegerOne+IntegerTwo;
cout << Answer;
}
if (Operand == '-')
{
Answer=IntegerOne-IntegerTwo;
cout << Answer;
}
if (Operand == '*')
{
Answer=IntegerOne*IntegerTwo;
cout << Answer;
}
if (Operand == '/')
{
Answer=IntegerOne/IntegerTwo
cout << Answer;
}
if (Operand == '%')
{
Answer=IntegerOne%IntegerTwo;
cout << Answer;
}
What exactly does not work? this code is valid C++, which should solve your problem. I thested it and it Does work:
Enter equation to be performed --> 232 / 5
46
Enter equation to be performed --> N
Process returned 0 (0x0) execution time : 9.847 s
Press any key to continue.