Ok, The problem is that when I execute this program (C++) what ever numbers I put into the answer slot it is given me the answer to the numbers of what ever I choose whether it would be Add, Subtract, Multiply or Divide as a Sum and not Difference or Product or Quotient. And it is not working as what I am asking it to do. Like if I pick Division it is adding the two numbers or if I pick Multiply it is still adding the two numbers.
Not sure what is going on.
//This program will add, subtract, multiply or divide depending on what the user inputs
#include <iostream>
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;
cout <<"Enter first number: ";
cin >> num1;
cout <<"Enter second number: ";
cin >> num2;
operation = toupper(operation);
if (operation != 'A' && operation != 'S' && operation != 'M' && operation != 'D')
//Changed this to && instead of ||
{
cout <<"Error: Wrong letter entered" << endl;
return 0;
}
if (operation == 'A' || 'a')
{
answer = num1 + num2;
cout << "Sum: " << answer << endl;;
}
else if (operation == 'S' || 's')
{
if (num1 > num2)
{
answer = num1 - num2;
cout << "Difference: " << answer << endl;
}
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