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