一个四则运算小游戏的程序,请各位大神看看是哪写错了
#include<stdio.h>#include<stdlib.h>
#include<time.h>
void plus();
void minus();
void times();
void divide();
int config(int ans,int rit);
int main(void)
{
int i;
for(;;)
{system("cls");
printf("\n calculation game\n");
printf("**********************\n");
printf("1.plus calculation\n");
printf("2.minus calculation\n");
printf("3.times calculation\n");
printf("4.division calculation\n");
printf("0.exit\n");
printf("**********************\n");
fflush(stdin);//trying
scanf("%d",&i);
switch(i){
case 1:plus();break;
case 2:minus();break;
case 3:times();break;
case 4:divide();break;
case 0:exit(0);break;}
}
return 0;
}
void plus()
{
int i=-1,seed,a,b,c,ans;char n;
for(;i==0;)
{seed=time(0);system("cls");
printf("1.calculation above 10.\n2.calculation above 100\n0.exit\n");fflush(stdin);
scanf("%d",&i);
if(i==1)
{
srand(seed);
for(;;){ a=rand()%10;b=rand()%10;
c=a+b;
printf("\n%d+%d=",a,b);fflush(stdin);
scanf("%d",&ans);
if(config(ans,c))printf("\nyou're right\n");
else printf("you're wrong\n");
printf("would you like to continue? (Y/N)\n");
while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
}
}
else if(i==2)
{
srand(seed);
for(;;){ a=rand()%100;b=rand()%100;
c=a+b;
printf("\n%d+%d=",a,b);fflush(stdin);
scanf("%d",&ans);
if(config(ans,c))printf("\nyou're right\n");
else printf("you're wrong\n");
printf("would you like to continue? (Y/N)\n");
while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
}
}
}
END:printf("\npress any key to continue\n");getchar();
}
void minus()
{
int i=-1,seed,a,b,c,ans;char n;
for(;i==0;)
{seed=time(0);system("cls");
printf("1.calculation above 10.\n2.calculation above 100\n0.exit\n");
scanf("%d",&i);
if(i==1)
{
srand(seed);
for(;;){ a=rand()%10;b=rand()%10;if(a<b){c=a;a=b;b=c;}
c=a-b;
printf("\n%d-%d=",a,b);
scanf("%d",&ans);
if(config(ans,c))printf("\nyou're right\n");
else printf("you're wrong\n");
printf("would you like to continue? (Y/N)\n");
while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
}
}
else if(i==2)
{
srand(seed);
for(;;){ a=rand()%100;b=rand()%100;if(a<b){c=a;a=b;b=c;}
c=a-b;
printf("\n%d-%d=",a,b);
scanf("%d",&ans);
if(config(ans,c))printf("\nyou're right\n");
else printf("you're wrong\n");
printf("would you like to continue? (Y/N)\n");
while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
}
}
}
END:printf("\npress any key to continue\n");getchar();
}
void divide()
{
int i=-1,seed,a,b,c,ans;char n;
for(;i==0;)
{seed=time(0);system("cls");
printf("1.calculation above 10.\n2.calculation above 100\n0.exit\n");
scanf("%d",&i);
if(i==1)
{
srand(seed);
for(;;){ a=rand()%10;b=rand()%10;if(a<b){c=a;a=b;b=c;}if(a%b)a-=a%b;
c=a/b;
printf("\n%d/%d=",a,b);
scanf("%d",&ans);
if(config(ans,c))printf("\nyou're right\n");
else printf("you're wrong\n");
printf("would you like to continue? (Y/N)\n");
while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
}
}
else if(i==2)
{
srand(seed);
for(;;){ a=rand()%100;b=rand()%100;if(a<b){c=a;a=b;b=c;}if(a%b)a-=a%b;
c=a/b;
printf("\n%d/%d=",a,b);
scanf("%d",&ans);
if(config(ans,c))printf("\nyou're right\n");
else printf("you're wrong\n");
printf("would you like to continue? (Y/N)\n");
while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
}
}
}
END:printf("\npress any key to continue\n");getchar();
}
void times()
{
int i=-1,seed,a,b,c,ans;char n;
for(;i==0;)
{seed=time(0);system("cls");
printf("1.calculation above 10.\n2.calculation above 100\n0.exit\n");
scanf("%d",&i);
if(i==1)
{
srand(seed);
for(;;){ a=rand()%10;b=rand()%10;
c=a*b;
printf("\n%d*%d=",a,b);
scanf("%d",&ans);
if(config(ans,c))printf("\nyou're right\n");
else printf("you're wrong\n");
printf("would you like to continue? (Y/N)\n");
while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
}
}
else if(i==2)
{
srand(seed);
for(;;){ a=rand()%100;b=rand()%100;
c=a*b;
printf("\n%d*%d=",a,b);
scanf("%d",&ans);
if(config(ans,c))printf("\nyou're right\n");
else printf("you're wrong\n");
printf("would you like to continue? (Y/N)\n");
while(1){if(getchar()=='N')goto END;else if(getchar()=='Y')break;else printf("\b");}
}
}
}
END:printf("\npress any key to continue\n");getchar();
}
int config(int ans,int rit)
{
return ans==rit?1:0;
}
plus()等四个函数的for循环好像没运行,然后直接就跳出了……各位大神求指教啊