我目前正在尝试创建一个快速程序,让您有机会在 10 次猜测中猜出预定数字(我希望该数字为 28)。如果你猜对了,你会被告知“恭喜!你猜对了这个数字。”如果你不符合猜测,你会被告知“再试一次!”直到您尝试次数耗尽或猜对为止。
这是我当前的代码: int main(void) {
int Chance, Guess;
printf ("You have 10 chances to guess the number between 0-50.\n");
for (Chance=0; Chance<10; Chance++)
{
scanf("%d",&Guess);
If (Guess==28)
printf("Congrats! You have guess the number!");
Else If (Guess!=28)
printf("Try Again!\n");
}
printf("You are all out of tries.");
return 0;
}
这是我的错误列表: 编译错误时间: 0内存:0信号:0
prog.c:在函数“main”中:
prog.c:9:3:警告:函数“If”的隐式声明 [-Wimplicit-function-declaration] 如果(猜==28) ^
prog.c:10:4: 错误:预期为“;”在“printf”之前 printf("恭喜!你猜对了!"); ^
prog.c:11:3: 错误:未知类型名称“Else” 否则如果(猜猜!=28) ^ prog.c:11:17: 错误:'!=' 标记之前应有 ')' 否则如果(猜猜!=28) ^
任何帮助将不胜感激!
最佳答案
if
和 else
子句以小写字母开头。实际上,所有 C 和 C++ 保留字都以小写字母或下划线开头。
C 和 C++ 语言都区分大小写。
关于c++ - 函数的隐式声明 'If',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28440730/