Credit to Kareem for answering this question, but it has been 4 months and it hasn't been posted as an answer... in the interest of improving the CS50 knowledge base, I'm posting the answer here. (I arrived at this question by searching for unanswered questions to help with involving pset1.)
1 while (owed > quarter)
2 {
3 change++;
4 }
printf("%f\n", change);
Let's start at line 1.
while (owed > quarter)
When your computer evaluates this line, it will be either "true" or "false." If it is false, no big deal; the loop will not run, and you can move on with your code.
But let's see what happens if it evaluates to true. The computer will move on and execute whatever is inside the brackets:
{
change++;
}
and so it will find your "change" variable and increase it by 1. Then it will proceed back to the original "while" condition to evaluate it again...
But nothing has changed! "owed" is still greater than "quarter." While it's true that "change" is increased by 1, "changed" is not being evaluated.
So the computer will find that "owed > quarter" evaluates to "true" again, and execute the loop a second time... then a third time...
And so on infinitely.
To get your virtual machine to quit running that program without closing your browser, you can press "Ctrl +C."
while
loop because once the continuation condition of this loop is evaluated totrue
, it never becomesfalse
as neitherowed
norquarter
ever change inside the loop.