私は C が初めてで、既に知っていることを練習するためだけにこのゲームを作成しています。コードをある関数から別の関数に移動させる方法がよくわかりません(おそらく関数の呼び出しと呼ばれますか?)。私はそれを数回コンパイルしてテストしましたが、毎回少なくとも1つのことがうまくいかず、盲目的に(おそらく良い考えではありませんでした)、今は続けることができません. まだ終わっていません。
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int response;
int loyalty = 0;
int level = 1;
int howmany;
int dothemnow;
int squad1;
int responsetwo;
int pushup;
char name [20];
int main(){
pushup=1;
dothemnow=0;
howmany=0;
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");
sleep (2);
printf("You are in a army excersize yard.\n");
sleep (2);
printf("Your sargeant approaches.\n");
sleep (2);
printf ("Sargeant Sam: Drop and give me five, Private %s\n",name);
printf ("1)Yessir!\n2)Make me\n");
scanf ("%d", &response);
if(response==1){
while(howmany<4 && pushup==1){
printf ("You do a pushup.\n");
howmany ++;
sleep(1);
printf ("You have done %d pushups\n",howmany);
printf ("Do another?\n1) yes\n2) no\n");
scanf ("%d",&pushup);
}
}
if(howmany==5){
/*Make it so it goes to the war function*/
int war();
}
if(pushup==2 && dothemnow!=2){
dothemnow ++;
printf("Sargeant Sam: Do them NOW!!!\n");
sleep(2);
printf ("1)Why?\n2)Ok,ok\n");
scanf ("%d",&responsetwo);
}
if(responsetwo==1){
while(howmany<4 && pushup==1){
printf ("You do a pushup.\n");
howmany ++;
sleep(1);
printf ("You have done %d pushups\n",howmany);
printf ("Do another?\n1) yes\n2) no\n");
scanf ("%d",&pushup);
}
}
if(howmany==5){
int war();
}
if(pushup==2){
dothemnow ++;
}
if(responsetwo==2){
while(howmany<4 && pushup==1){
printf ("You do a pushup.\n");
howmany ++;
sleep(1);
printf ("You have done %d pushups\n",howmany);
printf ("Do another?\n1) yes\n2) no\n");
scanf ("%d",&pushup);
}
}
if(howmany==5){
int war();
}
if(pushup==2){
dothemnow ++;
}
if(response==2){
dothemnow ++;
printf("Sargeant Sam: Do them NOW!!!\n");
sleep(2);
printf ("1)Why?\n2)Ok,ok\n");
scanf ("%d",&responsetwo);
}
if(responsetwo==1){
dothemnow ++;
}
if(responsetwo==2)
while(howmany<4 && pushup==1){
printf ("You do a pushup.\n");
howmany ++;
sleep(1);
printf ("You have done %d pushups\n",howmany);
printf ("Do another?\n1) yes\n2) no\n");
scanf ("%d",&pushup);
if(pushup==2){
dothemnow ++;
}
if(howmany==5){
int war();
}
}
if(dothemnow==2){
printf ("You are under military arrest!\n");
}
return 0;
}
int war(){
printf ("Loading...");
sleep (2);
printf ("Seargant Sam: Great job Private %s.\n",name);
sleep (2);
printf ("You are hereby promoted to Corporal");
sleep (2);
printf ("****LEVEL UP!****\n");
sleep (1);
level ++;
printf ("You are now level %d!\n",level);
sleep (1);
printf ("Do you want to be friendly or strict to your squad?\n1) Friendly\n2) Strict\n");
scan("%d", squad1);
if(squad1==1){
loyalty --;
}
if(squad1==2)
loyalty ++;
}
printf ("Seargant Sam: You will be deployed to Afganistan in one week, Corporal %s.\n",name);
sleep (1);
printf ("In the mean time, get to know your sqaud.\n");
sleep (1);
printf ("There are ten about 20 to 25 year olds in front of you\n");
sleep (1);
printf ("1)Nod\n2)'Laugh' Well I guess I'm the boss of you now\n3)Salute\n4)Drop and give me twenty!\n");
scanf ("%d", &squad2);
switch(squad2){
case 1:
printf ("They nod back");
case 2:
loyalty - 2;
printf ("They all smile and laugh a little");
break;
case 3:
loyalty + 2;
printf ("They all salute back");
sleep(1)
printf ("'As you were', you say");
break;
case 4:
loyalty + 3;
printf ("They do the pushups");
break;
}
printf ("Seargant Sam: Show them to their cabin, Corporal.");
sleep (1);
printf("You walk to the cabin.\n");
sleep (1);
if(loyalty>0){
printf ("One of the soldiers in your squad, Private Smith, who looks wiry but strong, says 'Corporal, you seem like a cool guy, but how did you get promoted to corporal?'");
sleep (1);
printf ("Ha, I see how you could be confused");
sleep (1);
printf ("Well, I don't really know either, I just did five pushups, and wahla, Corporal.");
}
}
したがって、これをコンパイルしようとすると、エラーが発生します。
game1.c:136: error: expected declaration specifiers or ‘...’ before string constant
game1.c:136: error: expected declaration specifiers or ‘...’ before ‘name’
game1.c:136: warning: data definition has no type or storage class
game1.c:136: error: conflicting types for ‘printf’
game1.c:136: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:137: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:137: warning: data definition has no type or storage class
game1.c:138: error: expected declaration specifiers or ‘...’ before string constant
game1.c:138: warning: data definition has no type or storage class
game1.c:138: error: conflicting types for ‘printf’
game1.c:138: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:139: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:139: warning: data definition has no type or storage class
game1.c:140: error: expected declaration specifiers or ‘...’ before string constant
game1.c:140: warning: data definition has no type or storage class
game1.c:140: error: conflicting types for ‘printf’
game1.c:140: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:141: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:141: warning: data definition has no type or storage class
game1.c:142: error: expected declaration specifiers or ‘...’ before string constant
game1.c:142: warning: data definition has no type or storage class
game1.c:142: error: conflicting types for ‘printf’
game1.c:142: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:143: error: expected declaration specifiers or ‘...’ before string constant
game1.c:143: error: expected declaration specifiers or ‘...’ before ‘&’ token
game1.c:143: warning: data definition has no type or storage class
game1.c:143: error: conflicting types for ‘scanf’
game1.c:143: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:144: error: expected identifier or ‘(’ before ‘switch’
game1.c:166: error: expected declaration specifiers or ‘...’ before string constant
game1.c:166: warning: data definition has no type or storage class
game1.c:166: error: conflicting types for ‘printf’
game1.c:166: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:167: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:167: warning: data definition has no type or storage class
game1.c:168: error: expected declaration specifiers or ‘...’ before string constant
game1.c:168: warning: data definition has no type or storage class
game1.c:168: error: conflicting types for ‘printf’
game1.c:168: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:169: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:169: warning: data definition has no type or storage class
game1.c:170: error: expected identifier or ‘(’ before ‘if’
game1.c:181: error: expected identifier or ‘(’ before ‘}’ token
関数戦争にあるとは言っていないことに注意してください。