这是我来自pset1 Cash问题的代码。 它会提出问题,并且会一直询问直到得到正确答案为止。 现在,它没有继续其余的过程。程序一旦回答就停止。
#include<stdio.h>
#include<cs50.h>
#include<math.h>
int main(void)
{
float money;
int coins;
int i;
do
{
//asking customer
money = get_float("How much change is owed? ");
}
while(money <= 0);
coins = round(money * 100);
for (i=0; coins == 0; i++)
{
//quarters
if (coins >= 25)
{
coins = coins - 25;
}
//dimes
else if (coins >= 10)
{
coins = coins - 10;
}
//nickels
else if (coins >= 5)
{
coins = coins - 5;
}
//pennies
else if (coins >= 1)
{
coins = coins - 1;
}
else
{
(printf("%i", i));
}
}