/程序功能:一开始程序自动进入第一轮运算测试,通过按“p”“m”“t”“d”而选择加、减、乘、除运算,再每做完一道题
时按回车继续该运算,按“p”“m”“t”“d”进行相应运算切换,其间可按“s”退出该轮测试;
若按了“s”则选择是否进行下一轮,按分别按“y”“n”表示是或不是。/
# include <stdioh>
# include <timeh>
# include <stdlibh>
void main()
{int p[2]={0},m[2]={0},t[2]={0},d[2]={0},i=0,j=0,k=0;//数组分别存放每轮做相应运算的总数和正答个数;k、j分别记所做轮数和每轮所做的题数
char c,exit='y';
void pluss(int p);
void minus(int m);
void times(int t);
void division(intt);
void test(intp,intm,intt,intd);
while(exit!='n'){ //输出提示语
printf("\n 按 \"p\"--->\"+\"运算; 按 \"m\"--->\"-\"运算;\n 按 \"t\"--->\"\"运算; 按 \"d\"--->\"/\"运算;");
printf(" 按 \"s\"--->\"退出该轮测试\"\n 做完每道题后您可按回车键继续该运算或切换到别的运算");
printf("\n\n欢迎进入第%d轮测试 请选择运算 ",++k);
c=getchar();
if(k!=1)c=getchar();//选择运算
while(c!='s'){
while(c=='p'||(c!='s'&&c!='m'&&c!='t'&&c!='d')){printf("第%d道 ",++j);pluss(p);c=getchar();c=getchar();}
while(c=='m'||(c!='s'&&c!='p'&&c!='t'&&c!='d')){printf("第%d道 ",++j);minus(m);c=getchar();c=getchar();}
while(c=='t'||(c!='s'&&c!='m'&&c!='p'&&c!='d')){printf("第%d道 ",++j);times(t);c=getchar();c=getchar();}
while(c=='d'||(c!='s'&&c!='m'&&c!='t'&&c!='p')){printf("第%d道 ",++j);division(d);c=getchar();c=getchar();}
}
test(p,m,t,d); //按s后退出一轮测试,调用函数给出测试结果
printf("\n 按 \"y\"---> \"进入第%d轮\" 按 \"n\"---> \"退出程序\" ",k+1);
exit=getchar();exit=getchar();
if(exit!='n'){ //按s后选则是否进入下一轮
j=0;
for(i=0;i<2;i++)p[i]=m[i]=t[i]=d[i]=0;
}
}
printf("\n\n Bye-Bye\n\n");
}
void pluss(int p){
int y,x,sum;
srand (time(NULL));
x=(int)rand()%10+1;
y=(int)rand()%10+1;
printf("%d+%d=",x,y);
scanf("%d",&sum);
p[0]++;
if(sum==x+y){printf("Congratuations! ");p[1]++;}
else printf("Sorry! Right answer is %d ",x+y);}
void minus(int m){
int y,x,minus;
srand (time(NULL));
x=(int)rand()%10+1;
y=(int)rand()%10+1;
m[0]++;
printf("%d-%d=",x+y,y);
scanf("%d",&minus);
if(minus==x){printf("Congratulations! ");m[1]++;}
else printf("Sorry! Right answer is %d ",x);
}
void times(int t){
int y,x,tim;
srand (time(NULL));
x=(int)rand()%10+1;
y=(int)rand()%10+1;
printf("%d%d=",x,y);
scanf("%d",&tim);
t[0]++;
if(tim==xy){printf("Congratulations! ");t[1]++;}
else printf("Sorry! Right answer is %d ",xy);
}
void division(int d){
int y,x,div;
srand (time(NULL));
x=(int)rand()%10+1;
y=(int)rand()%10+1;
printf("%d/%d=",xy,y);
scanf("%d",&div);
d[0]++;
if(div==x){printf("Congratulations! ");d[1]++;}
else printf("Sorry! Right answer is %d ",x);
}
void test(int p,intm,intt,intd){
int s[2];
float rate;
s[0]=p[0]+m[0]+t[0]+d[0];
s[1]=p[1]+m[1]+t[1]+d[1];
rate=s[1]/(s[0]10);
if(rate>08)printf("\nYou have done a good job !\n\n");
else if(rate<06)printf("\nYou have done a bad job !\n\n");
else printf("\nCome on! You can do it better !\n\n");
if(s[0]!=0)
printf("total done:%d right:%d rate:%52f%c\n",s[0],s[1],rate100,'%');
else printf("total done:0 right:0\n");
if(p[0]!=0)
printf("\"+\" done:%d right:%d rate:%52f%c ",p[0],p[1],(p[1]/(p[0]10))100,'%');
else printf("\"+\" done:%d right:%d ",p[0],p[1]);
if(m[0]!=0)
printf("\"-\" done:%d right:%d rate:%52f%c\n",m[0],m[1],(m[1]/(m[0]10))100,'%');
else printf("\"-\" done:%d right:%d\n",m[0],m[1]);
if(t[0]!=0)
printf("\"\" done:%d right:%d rate:%52f%c ",t[0],t[1],(t[1]/(t[0]10))100,'%');
else printf("\"\" done:%d right:%d ",t[0],t[1]);
if(d[0]!=0)
printf("\"/\" done:%d right:%d rate:%52f%c\n",d[0],d[1],(d[1]/(d[0]10))100,'%');
else printf("\"/\" done:%d right:%d\n",d[0],d[1]);
}
找过来的,运行下看看是否可行。
Private Sub Form_Load()
Form1Caption = "学号,姓名"
Call Command2_Click
End Sub
Private Sub Command1_Click()
Label1Caption = Val(Text1) + Val(Text2)
End Sub
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Label1Caption = ""
End Sub
Private Sub Command3_Click()
End
End Sub
以上就是关于用C语言设计一个儿童四则运算程序,根据用户的设定自动出题并对全部回答进行判断,全部答完后统计正确率全部的内容,包括:用C语言设计一个儿童四则运算程序,根据用户的设定自动出题并对全部回答进行判断,全部答完后统计正确率、用VB编写一个数学计算程序,完成数学公式 的计算。、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)