|
-
September 6th, 2012, 05:15 AM
#4
Re: Returning Operator to Switch Statement
 Originally Posted by basanta
Couldn't not understand. I was just trying to print the error message until user give right operator from list. I am pretty much confused can switch in main recognize the operator return from this function ?
C++ isn't the same as speaking English. Learn what boolean operators "&&" and "||" are supposed to do.
Look carefully at the logic of your if() statement. Assume that oper is a '*'. Read your if() statement again, carefully:
Since oper is a '*', then it is not a '+'. Since the very first part of that if() statement says "if operator is not a '+'", then guess what? That entire if() statement is true, since the very first condition is true. All of those conditions are separated with ||, so just one of those conditions being true means everything is true.
C++ is not the same as speaking English. When we talk to each other and say "or this or that or the other", then yes, we mean all of them. But for C++ and most programming languages, the term "||" and "&&" has a specific meaning and function.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|