【发布时间】:2016-02-13 09:32:12
【问题描述】:
我不明白为什么第一个循环不起作用。即使填充的欠浮动实际上大于0也是一个无限循环。为什么循环不起作用?
#import <cs50.h>
#import <stdio.h>
int main(void)
{
float owed = -1 ;
while (owed < 0)
{
printf("O hai! How much change is owed?\n") ;
float owed = GetFloat() ;
owed = owed * 100 ;
}
int coins = 0 ;
while (owed >= 25)
{
owed = owed - 25 ;
coins = coins + 1 ;
}
while (owed >= 10)
{
owed = owed - 10 ;
coins = coins + 1 ;
}
while (owed >= 5)
{
owed = owed - 5 ;
coins = coins + 1 ;
}
while (owed >= 1)
{
owed = owed - 1 ;
coins = coins + 1 ;
}
printf("%i\n", coins) ;
}
【问题讨论】:
-
GetFloat()的代码在哪里?