Do...While Correction Needed
I just recently started learning this stuff so I am sure I am doing something simple but I don't really notice a difference from my book examples. I am trying to have the program loop back to ask the original question "Enter and operation: + - * / (or enter X to exit): " but instead it loops through the if statement. So it keeps asking me for a number instead of a new operator and THEN a new number, but it's not actually performing the math either. This program is supposed to continuously perform math to a number until you press "X" to stop.
Code:
do
{
cout << "Enter and operation: + - * / (or enter X to exit): "; cin >> oper;
if (oper = '+')
{
cout << "Enter a number: "; cin >> num;
tot = tot + num;
cout << "Current total is " << tot << endl;
}
if (oper = '-')
{
cout << "Enter a number: "; cin >> num;
tot = tot - num;
cout << "Current total is " << tot << endl;
}
if (oper = '*')
{
cout << "Enter a number: "; cin >> num;
tot = tot * num;
cout << "Current total is " << tot << endl;
}
if (oper = '/')
{
cout << "Enter a number: "; cin >> num;
tot = tot / num;
cout << "Current total is " << tot << endl;
}
else cout << "Enter a valid number." << endl;
}
while (oper != 'X' || oper != 'x');