需要帮助:D
所以尝试着手为我的时间表测验 brother.Very new to coding 所以尽量做到简单 可能但真的卡住了。任何帮助都是极好的 基本上我一直收到这个错误
[ 在函数“main”中:第 17 行:错误:“else”之前的预期表达式]
#include <stdio.h>
int main (){
int answers_eight[] = {8,16,24,32,40,48,56,64,72,80,88,96};
int answer ;
printf ("8x1 = : ");
scanf ("%d",&answer);
If (answer == '8');
{
printf ("Correct");
}
else
{
printf ("Incorrect");
}
return 0;
}
最佳答案
您的代码有各种语法错误(If
而不是 if
,if 条件后的分号)。此外,您的代码在读取 int 然后与字符串进行比较时存在逻辑问题。此版本有效且缩进正确:
#include <stdio.h>
int main (){
int answers_eight[] = {8,16,24,32,40,48,56,64,72,80,88,96};
int answer ;
printf ("8x1 = : ");
scanf ("%d",&answer);
if (answer == 8) {
printf ("Correct");
} else {
printf ("Incorrect");
}
return 0;
}
关于c - 时间表测验(错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30867284/