哪位大大能给这段代码加个详细备注吗,谢谢!(教小学生学算术)
#include<stdio.h>#include<stdlib.h>
#include<time.h>
void menu()
{
printf("********************************************************************************");
printf("^_^_^_^_^_^_^_^_^_^_^_^小朋友,欢迎你们来学习小学算术_^_^_^_^_^_^_^_^_^_^_^_^_^_");
printf(" ");
printf(" 1.加法 ");
printf(" 2.减法 ");
printf(" 3.乘法 ");
printf(" 4.除法 ");
printf(" 0.退出 ");
printf(" ");
printf(" 快选择你要学习的内容吧! ");
printf(" ");
printf("^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_^_");
printf("********************************************************************************");
}
void plus1()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第一关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
printf("%d",m=rand()%10);
printf("+");
printf("%d",n=rand()%10);
printf("=");
total=m+n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第一关!\n");
}
}
void plus2()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第二关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
do{
m=rand()%10;
n=rand()%100;
}while(n<10);
printf("%d",m);
printf("+");
printf("%d",n);
printf("=");
total=m+n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第二关!\n");
}
}
void plus3()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第三关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
do{
m=rand()%100;
n=rand()%100;
}while(m<10&&n<10);
printf("%d",m);
printf("+");
printf("%d",n);
printf("=");
total=m+n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第三关!\n");
}
}
void sub1()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第一关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
do{
m=rand()%10;
n=rand()%10;
}while(m<=n);
printf("%d",m);
printf("-");
printf("%d",n);
printf("=");
total=m-n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第一关!\n");
}
}
void sub2()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第二关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
do{
m=rand()%100;
n=rand()%10;
}while(m<10);
printf("%d",m);
printf("-");
printf("%d",n);
printf("=");
total=m-n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第二关!\n");
}
}
void sub3()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第三关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
do{
m=rand()%100;
n=rand()%100;
}while(m<=n||m<10||n<10);
printf("%d",m);
printf("-");
printf("%d",n);
printf("=");
total=m-n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第三关!\n");
}
}
void plus()
{
int i;
plus1();
printf("是否继续挑战?Y(1)/N(0):");
scanf("%d",&i);
if(i==1)
plus2();
else
return;
i=NULL;
printf("是否继续挑战?Y(1)/N(0):");
scanf("%d",&i);
if(i==1)
plus3();
else
return;
}
void sub()
{
int i;
sub1();
printf("是否继续挑战?Y(1)/N(0):");
scanf("%d",&i);
if(i==1)
sub2();
else
return;
i=NULL;
printf("是否继续挑战?Y(1)/N(0):");
scanf("%d",&i);
if(i==1)
sub3();
else
return;
}
void mul1()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第一关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
printf("%d",m=rand()%10);
printf("*");
printf("%d",n=rand()%10);
printf("=");
total=m*n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第一关!\n");
}
}
void mul2()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第二关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
do{
m=rand()%100;
n=rand()%10;
}while(m<10);
printf("%d",m);
printf("*");
printf("%d",n);
printf("=");
total=m*n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第二关!\n");
}
}
void mul()
{
int i;
mul1();
printf("是否继续挑战?Y(1)/N(0):");
scanf("%d",&i);
if(i==1)
mul2();
}
void div1()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第一关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
do{
m=rand()%10;
n=rand()%10;
}while(n==0||m%n!=0);
printf("%d",m);
printf("/");
printf("%d",n);
printf("=");
total=m/n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第一关!\n");
}
}
void div2()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第二关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
do{
m=rand()%100;
n=rand()%10;
}while(n==0||m<10||m%n!=0);
printf("%d",m);
printf("/");
printf("%d",n);
printf("=");
total=m/n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第二关!\n");
}
}
void div3()
{
int count=0,m,n,s,total,k;
printf("欢迎进入第三关!\n");
printf("请设定题目数量:");
scanf("%d",&k);
while(count<k){
do{
m=rand()%100;
n=rand()%100;
}while(n==0||m<10||n<10||m%n!=0);
printf("%d",m);
printf("/");
printf("%d",n);
printf("=");
total=m/n;
loopa:scanf("%d",&s);
if(s==total)
{printf("恭喜你,答对了!\n");count++;}
else
{printf("回答错误,请重新回答!\n");goto loopa;}
printf("恭喜你通过了第三关!\n");
}
}
void div()
{
int i;
div1();
printf("是否继续挑战?Y(1)/N(0):");
scanf("%d",&i);
if(i==1)
div2();
else
return;
i=NULL;
printf("是否继续挑战?Y(1)/N(0):");
scanf("%d",&i);
if(i==1)
div3();
else
return;
}
main()
{
void menu();
int k;
do{
menu();
printf("请选择:");
scanf("%d",&k);
switch(k)
{
case 1:plus();break;
case 2:sub();break;
case 3:mul();break;
case 4:div();break;
case 0:break;
}
printf("\n");
}while(k!=0);
printf("\n");
return 0;
}