Normally you put a boolean expression inside the parentheses of if statements.
A boolean expression is something that gives you true or false.
Example: x < 5 is a boolean expression. It returns true if x is less than 5, otherwise it returns false.
If the boolean expression of an if statement is true it will execute the statement that follows, otherwise it will execute the statement in the else-part (if there is one).
1 2 3 4
|
if (condition)
runIfConditionIsTrue();
else
runIfConditionIsFalse();
|
When you use an integer instead of a boolean expression it will handle an integer value of zero the same way as the boolean value false. All integer values other than zero is handled the same way as true.
1 2 3 4
|
if (integer)
runIfIntegerIsNotZero();
else
runIfIntegerIsZero();
|
In your code you are using a char, and a char is just an integer type, so it will handle it the same way as described above. Because choice is set to 'A' it is never zero so it will never execute what's in the else-part. It will only execute the result=num*gain*gain part of the if statement.
Note when I say zero here I'm talking about the integer value zero and not the character zero. The character '0' is represented by some integer value other than zero. To set choice equal to zero you could use the integer literal 0.
But 0 has type int. When working with characters we often use '\0' which has type char.
The '\0' character is usually called a null character. Its main use is to mark the end of strings.