Can someone explain true false in c programming pertaining to this while loop?
If 0 is false Done=0, and
printf("Hot Dog. $2.00\n");
printf("Your choices are finished.\n");
printf("The total is:$%.2f\n", total);
printf("Please pay the cashier.\n");
printf("I don't understand your choice, please try again.\n");
Welcome to StackOverflow M.B.
while loop in C evaluates whatever is in it as either
false, before every loop.
One of the guarantees you get when programming in C is that only 0 is false, and everything else is true. That means that
foobar is true,
64 is true,
-1 is true, and in your case,
1 is true.
Because of this, the
! operator (the
not symbol), it changes anything that is true into a
0, and changes a
0 into a
Therefore, what your while loop is really doing is saying:
"While not done"
or "While done is not true"
or "While done is false"
or "While done is 0"
So when your last case statement of
'=' is hit, and the code
done=1; is run, you code will exit the next time it comes around and checks the condition for the while loop.