hey guys, I'm trying to learn C++, I don't have any prior programming experience except scripting in matlab.
One of the first programs I'm trying to make is a simple calculator that takes 2 inputs and an operator from the user and outputs a result. I got the program working, but I would like to modify it to include a check for a valid operator.
The operator is stored as a char variable, my first thought as to how to implement a check is with a loop:
However, the condition is always coming up as true, could someone explain why this is happening?
Thanks
One of the first programs I'm trying to make is a simple calculator that takes 2 inputs and an operator from the user and outputs a result. I got the program working, but I would like to modify it to include a check for a valid operator.
The operator is stored as a char variable, my first thought as to how to implement a check is with a loop:
Code:
While(mathoperator !=( '+' || '-' || '*' || '/'))
{
cout<<mathoperator<<" is not a valid operator, use +, -, *, /. Please try again:"<<endl;
cin>>mathoperator;
}
However, the condition is always coming up as true, could someone explain why this is happening?
Thanks
Last edited: