我的代码:
#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:语法错误:“类型”
这是cs50问题集1的一部分
1)您需要消除while()表达式中的“浮动更改”
2)您应该将“浮动更改”的声明移到顶部
#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)我还建议定义一个“最小值”,然后检查它:
#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
}
该行语法无效。将其更改为:
while (change < 0.00); //this is line 20