//Program adds, subtracts, multiplies, or divides any two numbers that the user enters.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
char operation = ' ';
int num1 = 0;
int num2 = 0;
int answer = 0;
cout <<"Enter A (add) or S (subtract) or M (multiply) or D (divide): ";
cin >> operation;
if (operation != 'A' || 'a' || 'S' || 's' || 'M' || 'm' || 'D' || 'd')
{
cout <<"Error: Wrong letter entered" << endl;
return 0;
}
cout <<"Enter first number: ";
cin >> num1;
cout <<"Enter second number: ";
cin >> num2;
if (operation == 'A' || 'a')
{
answer = num1 + num2;
cout <<"Sum: " << answer << endl;;
}//end if
if (operation == 'S' || 's')
{
if (num1 > num2)
{
answer = num1 - num2;
}//end if
else
answer = num2 - num1;
cout <<"Difference: " << answer << endl;
}//end if
if (operation == 'M' || 'm')
{
answer = num1 * num2;
cout <<"Product: " << answer << endl;
}//end if
if (operation == 'D' || 'd')
{
if (num1 > num2)
{
answer = num1 / num2;
}//end if
else
answer = num2 / num1;
cout <<"Quotient: " << answer << endl;
}//end if
return 0;
}//end of main function
I'm having trouble with the error message that I need to display at the beginning if the user enters an invalid letter. It's the first if statement.
It is suppose to display the error message if the user enters an invalid letter. Otherwise it should continue one and ask the user for the 2 numbers. What it does is it always dispalys the error message in cout and statements that as the user to enter the number never appear.
Any help appreciated!
Thanks. :)