#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Not the results I am looking for ** HELP **

Member Posts: 2
Ok, I have got my program working but it is displaying to many results. It is displaying the answer behind of the word Sum
. If I input 'M' then the answer is still displaying behind the word Sum
. Same thing for 'S' (for subtract) and 'D' (divide). Here is my code:

//This program will add, subtract, multiply or divide depending on what the user inputs

#include

using namespace std;

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;
operation = toupper(operation);

if (operation != 'A' && operation != 'S' && operation != 'S' && operation != 'M' && operation != '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;;

}

else if (operation == 'S' || 's')
{
if (num1 > num2)
{
answer = num1 - num2;
}
else
answer = num2 - num1;

cout <<"Difference: " << answer << endl;
}

else if (operation == 'M' || 'm')
{
answer = num1 * num2;
cout <<"Product: " << answer << endl;
}

else if (operation == 'D' || 'd')
{
if (num1 > num2)
{
answer = num1 / num2;
}
else
answer = num2 / num1;

cout <<"Quotient: " << answer << endl;
}

system("pause");
return 0;
}//end of main function

would someone please help me debug this program to find the problem? Thank you, Diana
Sign In or Register to comment.