No.
If you use && it means that all of the expresions have to evaluate to true for the whole test expression to be true, so that the statement following or the compound statement in braces will be executed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
unsigned short a =1;
unsigned short b =2;
if(a==1 && b == 2) { //both are true so do the code in the braces
//some code
}
else { //one of them is false. It will never happen
};
if(a==1 && b == 3) { b==3 is false, so code in braces wont happen
//this code is not executed
}
else {
//this code is executed
}
|
Now the || operator means that if any one of the expressions is true then the test expression is true.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
unsigned short a =1;
unsigned short b =2;
if(a==1 || b == 3) { a==1 is true, so code in braces will happen
//this code is executed
}
else {
//this code is not executed
}
if(a==4 || b == 3) {both are false, so code in braces will not happen
// this code is not executed
}
else {
//this code is executed
};
|
You can have else if expression in if statements as well, but if there are lots of them you are better doing switch statements instead.
These test expressions work the same way for all of the loop statements ( for, while, do while). The case expressions in a switch statement are constant expressions not comparisons.
I would reccommend that get hold of "C Programming" by Kernigan & Ritchie. It is a small book, but really worthwhile. I know of some professional programmers who still look at it, after years of writing code.
I can see that you have re written some of your code, and I still think it needs a major re organisation. I don't like all the nested loops and repeated tests. I know that you have probably spent a lot oif time on it, but it really is a case of throwing good money after bad as it were.
Think about what I mentioned earlier:
Here are some more clues: Use boolean values such as SeenFirstNum, SeenOperator, SeenSecondNum plus some others |
There are other types of calculators that do Reverse polish notation. This is not as hard as it sounds. Basically, instead of doing 1 + 2 =3 you do 1 2 + and the answer 3 is provided. This way, there is no need for parentheses, and it is easy to implement because all the operators take two arguments. Google.
TheIdeasMan