gpt4 book ai didi

c - main{} 括号上的语法错误, "expected while"?

转载 作者:太空宇宙 更新时间:2023-11-04 05:33:09 26 4
gpt4 key购买 nike

<分区>

我完全被难住了。无论我做什么,我的编译器都认为我在最后一个 printf 时需要一个 while 循环?它只是不断地要求一些没有意义的事情。当我添加它们时,它只是告诉我它不应该存在,当我删除它时,我被告知我需要它。

int main() {
float userInput; //The grades that the user inputs.
int passingGrade = 0; //Number of passing grades
int failingGrade = 0; //Failing grades
int invalidGrade = 0; //Invalid grades

//This do for loop is simply counting the number of grades of each catagory posted.
do {
printf("Enter a grade (Enter -1 to quit):");
scanf("%f", &userInput);
printf("You entered: %.1f\n", userInput);
if ((userInput > 100) || (userInput < 0)) { //Over 100 is impossible.
invalidGrade = invalidGrade + 1;
printf("You input an impossible grade!\n");
}
else {
if (userInput > 70) { //Greater than 70 means passing.
passingGrade = passingGrade + 1;
}
else {
if ((userInput < 70) && !(userInput < 0)) {
failingGrade = failingGrade + 1;
}
}
}
while (userInput != -1);
}
printf("You entered %i passing grades.\n", passingGrade);
printf("You entered %i failing grades.\n", failingGrade);
printf("You entered %i invalid grades.\n", invalidGrade);
system("pause"); }

代码运行得很好,并且完成了我期望它做的所有事情。但是编译器似乎认为它有问题。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com