-4

所以我正在尝试制作一个显示三个数字的基本程序,然后用户必须重新输入它们以测试他们的注意力。这可能只是因为我正在使用的编译器,但这似乎很奇怪。我在 main 结束时返回的地方遇到了解析错误。继承人的错误:

----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;
}
4

1 回答 1

3

第一个错误是什么?

错误:在“cYesNo”之前解析错误

你觉得这合适吗?

if(cYesNo == 'y' cYesNo == 'Y')

尝试添加 OR

if(cYesNo == 'y' || cYesNo == 'Y')

于 2014-10-26T22:06:15.663 回答