Intro to programming C

You wrote this:

    while (gross != 0);

But I think you meant this:

while (gross != 0)

A while statement followed by a ; is essentially a no-op — the body of the loop is empty. If you want to repeat all the code inside the braces, the while needs to come before the opening brace. The code from the opening brace { to the closing brace { is the “body” of the loop, i.e. the part that gets executed on every iteration of the loop.

Also, you should initialize gross to some value other than 0 so that you don’t exit the loop before you even get a chance to get a value. -1 would work for an initial value.

Browse More Popular Posts

Leave a Comment