2013-07-22 30 views
-7

我不明白這個C代碼有什麼問題。我只是問這是爲了學習的目的。我知道遊戲很愚蠢,但它只是爲了好玩和學習。這段代碼有什麼問題?

#include <stdio.h> 
int main(){ 
    int response 
    char name [20]; 
     printf ("Welcome to Game1\n"); 
     printf ("What's your name?\n"); 
     scanf ("%s",name); 
     printf ("From now on you're Private %s\n",name); 
     printf ("Loading...\n"); 
     delay(4000); 
     printf("You are in a army excersize yard.\n"); 
     delay(4000); 
     printf("Your sargeant approaches.\n"); 
     printf ("Sargeant Sam: Drop and give me twenty, Private %s\n",name); 
     printf ("1) Yessir!\n2)Make me\n"); 
     scanf ("%d\n", response); 
      if(response==1){ 
       printf ("You do 20 pushups\n"); 
      } 
      if(response==2){ 
      printf("Sargeant Sam: What did you say?!\n"); 
      } 
return (0); 
} 

這些都是錯誤

game1.c: In function ‘main’: 
game1.c:4: error: nested functions are disabled, use -fnested-functions to re-enable 
game1.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘char’ 
game1.c:16: error: ‘response’ undeclared (first use in this function) 
game1.c:16: error: (Each undeclared identifier is reported only once 
game1.c:16: error: for each function it appears in.) 

我是一個初學者,所以請簡單地解釋一切。

+1

請停止它的男人,請在重複發表相同的問題前努力學習。例如,你剛纔發佈了一個[question-2](http://stackoverflow.com/questions/17793445/what-does-undefined-symbols-for-architecture-x86-64-mean-in-c) qestion-2](http://stackoverflow.com/questions/17792702/when-compiling-ac-program-i-get-this-error-hello-no-such-file-or-directory) –

回答

4
int main(){ 
int response 
      ^

在這裏缺少分號。

3
int response 

聲明以分號結尾:;

此外,還有缺乏連貫indentationdelay不屬於C標準(在<stdio.h>未聲明)。

+1

其他職位打你15秒 – jdero

+0

對不起,這是一個可怕的帖子:(對不起,浪費你的時間,我現在不能發佈任何東西,因爲我的分數很低,現在我有一個很好的問題,我已經研究了很多,所以請讓這個更高。 – user2607534