c2059 do while loop C 错误,怎么了?

c2059 error in do while loop C, what's wrong?

我的代码:

#include "cs50.h"
#include <stdio.h>
#include <math.h>

int main (void)
{
    do
    {
        printf("How much money do I owe you ?\n");
        float change = GetFloat(); //gets a floating point value from the user
        if(change <0.01 )
        {
            printf("Try again you big dummy\n");
        }
        else
        {
            printf("Capitalism Ho!\n");
        }
    }
    while (float change < 0.00); //this is line 20
}

在编译器中:

greedo.c(20)错误2059:syntax错误:"type"

这是cs50问题集1的一部分

该行语法​​无效。将其更改为:

while (change < 0.00); //this is line 20

1) 您需要消除 while() 表达式中的 "float change"

2) 您应该将 "float change" 的声明移到顶部

#include "cs50.h"
#include <stdio.h>
#include <math.h>

int main (void)
{
    float change;
    do
    {
        printf("How much money do I owe you ?\n");
        change = GetFloat(); //gets a floating point value from the user
        if(change <0.01 )
        {
            printf("Try again you big dummy\n");
        }
        else
        {
            printf("Capitalism Ho!\n");
        }
    }
    while (change < 0.00); //this is line 20
}

3) 我还建议定义一个 "min value",然后对照它进行检查:

#include "cs50.h"
#include <stdio.h>
#include <math.h>

#define MIN_VALUE 0.01

int main (void)
{
    float change;
    do
    {
        printf("How much money do I owe you ?\n");
        change = GetFloat(); //gets a floating point value from the user
        if(change >= MIN_VALUE)
        {
            printf("Capitalism Ho!\n");
            break;
        }
    }
    while (change < MIN_VALUE); //this is line 20
}