所以我试图制作一个显示三个数字的基本程序,然后用户必须重新输入它们以测试它们的浓度。它可能只是因为我使用的编译器,但它似乎很奇怪。我在主要结束时返回时没有意义的地方得到解析错误。下面是错误:
----jGRASP exec: gcc -g -o Concentration.exe Concentration.c
Concentration.c: In function `main':
Concentration.c:28: error: parse error before "cYesNo"
Concentration.c: At top level:
Concentration.c:53: error: parse error before string constant
Concentration.c:53: warning: conflicting types for built-in function `printf'
Concentration.c:53: warning: data definition has no type or storage class
Concentration.c:54: warning: data definition has no type or storage class
Concentration.c:55: error: parse error before "return"
----jGRASP wedge2: exit code for process is 1.
这里也是代码:该文件名为Concetraion.c btw。
Pastebin:http://pastebin.com/GYmhefDE - 标记为私有,因此无法访问
Mediafire下载:http://www.mediafire.com/view/kf73fzfsifqfuzj
修改评论,但几乎没有MCVE:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
char cYesNo = 'z';
int guessNum1 = 0;
int guessNum2 = 0, guessNum3 = 0;
int randNuml = 0, randNum2 = 0, randNum3 = 0;
int elapsedTime = 0;
int currentTime = 0;
int counter = 0;
srand(time(NULL));
printf("Play a game of Concentration? (y or n): ");
scanf("%c", &cYesNo);
if(cYesNo == 'y' cYesNo == 'Y') // Line 28
{
randNuml = rand() % 100;
randNum2 = rand() % 100;
randNum3 = rand() % 100;
printf("\nConcentrate on the next three numbers\n");
printf("\n\t%d %d %d\n\n", randNuml , randNum2, randNum3);
currentTime = time(NULL);
do{
elapsedTime = time(NULL);
}while ((elapsedTime - currentTime) < 3);
system("cls");
printf("\nEnter each # separated with one space: ");
scanf("%d%d%d", &guessNum1, &guessNum2, &guessNum3);
if(randNuml == guessNum1 && randNum2 == guessNum2 && randNum3 == guessNum3)
printf("\nCongratulations!\n");
else
printf("\nSorry, correct numbers were: %d %d %d\n", randNuml, randNum2, randNum3);
}
printf("\nPress any key to quit"); // Line 53
getch();
return 0;
}
答案 0 :(得分:3)
第一个错误是什么?
错误:在“cYesNo”之前解析错误
这看起来对你好吗?
if(cYesNo == 'y' cYesNo == 'Y')
尝试添加OR
if(cYesNo == 'y' || cYesNo == 'Y')