if ( coin == 5)
totalcoin = totalcoin + 5;
printf("Amount depositied so far: $ %d\n", totalcoin);
The indentation does not show what it really does. It's actually equivalent to:
if ( coin == 5)
{
totalcoin = totalcoin + 5;
}
printf("Amount depositied so far: $ %d\n", totalcoin);
which is not what you mean, you should use a block:
if ( coin == 5)
{
totalcoin = totalcoin + 5;
printf("Amount depositied so far: $ %d\n", totalcoin);
}
As a best practice, some people choose to always use a block after if
, for
, while
, etc, even if there's only one statement in the block. It's less error prone, especially when you need to add more statements to it.