-4

そこで、3 つの数字を表示する基本的なプログラムを作成しようとしています。ユーザーはそれらを再入力して、集中力をテストする必要があります。使用しているコンパイラのせいかもしれませんが、奇妙に思えます。メインの最後のリターンで、意味をなさない場所で解析エラーが発生します。エラーは次のとおりです。

----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 という名前です。

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 に答える