刚学了函数..就要把开始的改编成函数形式的..到底什么是函数阿..?
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
main()
{ int s/*任务选择*/,i=0/*计数器*/,f=0/*计分器*/,c1/*数1*/,c2/*数2*/,o/*符号*/,j/*随机*/;
double c/*答案*/,p/*输入*/;
char F/*四则运算*/,x[100]/*字符串*/,z;
srand(time(NULL));
printf("欢迎使用计算机辅助教学系统!\n\n请选择要进行的任务(1~6):");
while(!(scanf("%d",&s) && s>=1 && s<=6))
printf("输入有误!请重新输入:");
switch(s)
{case 1:
do{c1=rand()%10+1,c2=rand()%10+1,c=c1*c2;
printf("%d*%d=",c1,c2);
while(!(scanf("%lf",&p) && p==c))
printf("\n\"Wrong!Please try again.\"\n\n%d*%d=",c1,c2);
printf("\n\"Right!\"\n\n");}while(1);
break;
case 2:
c1=rand()%10+1,c2=rand()%10+1,c=c1*c2;
printf("%d*%d=",c1,c2);
while(!(scanf("%lf",&p) && p==c))
{i++;
if(i==3)
{printf("\n\"Wrong!You have tried three times!Test over!\"\n\n");
break;}
printf("\n\"Wrong!Please try again.\"\n\n%d*%d=",c1,c2);}
if (p==c)
printf("\n\"Right!\"\n\n");
break;
case 3:
do{i++,c1=rand()%10+1,c2=rand()%10+1,c=c1*c2;
printf("%d*%d=",c1,c2);
scanf("%lf",&p);
if(p==c)
{printf("\n\"Right!\"\n\n");
f+=10;}
else printf("\n\"Wrong!\"\n\n");}
while(i!=10);
printf("你的总分为:%d分\n回答正确率为:%d%%\n",f,f);
break;
case 4:
do{i++,c1=rand()%10+1,c2=rand()%10+1,o=rand()%4;
if(o==0)
F='+',c=c1+c2;
else if(o==1)
F='-',c=c1-c2;
else if(o==2)
F='*',c=c1*c2;
else F='/',c=(double)c1/c2;
printf("%d%c%d=",c1,F,c2);
scanf("%lf",&p);
if(p==c)
{printf("\n\"Right!\"\n\n");
f+=10;}
else printf("\n\"Wrong!\"\n\n");}
while(i!=10);
printf("你的总分为:%d分\n回答正确率为:%d%%\n",f,f);
break;
case 5:
do{i=0,f=0;
do{i++,c1=rand()%10+1,c2=rand()%10+1,o=rand()%4;
if(o==0)
F='+',c=c1+c2;
else if(o==1)
F='-',c=c1-c2;
else if(o==2)
F='*',c=c1*c2;
else F='/',c=(double)c1/c2;
printf("%d%c%d=",c1,F,c2);
scanf("%lf",&p);
if(p==c)
{printf("\n\"Right!\"\n\n");
f+=10;}
else printf("\n\"Wrong!\"\n\n");}
while(i!=10);
printf("你的总分为:%d分\n回答正确率为:%d%%\n\n",f,f);
if (f<75)
printf("你的正确率低于75%%!请重新作答!\n\n");}
while(f<75);
break;
case 6:
do{i=0,f=0;
do{i++,c1=rand()%10+1,c2=rand()%10+1,o=rand()%4,j=rand()%4+7;
if(o==0)
F='+',c=c1+c2;
else if(o==1)
F='-',c=c1-c2;
else if(o==2)
F='*',c=c1*c2;
else F='/',c=(double)c1/c2;
printf("%d%c%d=",c1,F,c2);
scanf("%lf",&p);
if(j==7)
z='+';
else if(j==8)
z='-';
else if(j==9)
z='*';
else z='/';
switch(z){
case '+':
if(p==c)
strcpy(x,"Very good!");
else strcpy(x,"No.Please try again.");
goto x;
case '-':
if(p==c)
strcpy(x,"Excellent!");
else strcpy(x,"Wrong.Try once more.");
goto x;
case '*':
if(p==c)
strcpy(x,"Nice work!");
else strcpy(x,"Don't give up!");
goto x;
case '/':
if(p==c)
strcpy(x,"Keep up the good work!");
else strcpy(x,"Not correct.Keep trying.");
goto x;}
x: if(p==c)
{printf("\n\"%s\"\n\n",x);
f+=10;}
else printf("\n\"%s\"\n\n",x);}
while(i!=10);
printf("你的总分为:%d分\n回答正确率为:%d%%\n\n",f,f);
if (f<75)
printf("你的正确率低于75%%!请重新作答!\n\n");}
while(f<75);
break;
default:;}

}


把之前的一变就变了样,,感觉更复杂更麻烦了..


#include<stdio.h>

#include<stdlib.h>
#include<time.h>
#include<string.h>
int s/*任务选择*/,i=0/*计数器*/,f=0/*计分器*/,c1/*数1*/,c2/*数2*/,o/*符号*/,j/*随机*/;
double c/*答案*/,p/*输入*/;
char F/*四则运算*/,x[100]/*字符串*/;
int PDXT/*判断系统含正确率*/()
{
if(p!=c)
return 0;
else f+=10;
return 1;
}
void SZYS/*四则运算*/()
{
o=rand()%4;
if(o==0)
F='+',c=c1+c2;
else if(o==1)
F='-',c=c1-c2;
else if(o==2)
F='*',c=c1*c2;
else F='/',c=(double)c1/c2;
}
void PJXT/*评价系统*/(int a/*是否正确*/,int b/*类型1:普通;2:防疲劳;3:三次规则.*/)
{
j=rand()%4;
if(b==1 || b==3){
if(a==1){
i=0;
strcpy(x,"Right!");}
else {
i++;
if(b==3 && i==3)strcpy(x,"Wrong!You have tried three times!Test over!");
else strcpy(x,"Wrong!Please try again.");}}
else 
if(a==1){
if(j==0)strcpy(x,"Very good!");
else if(j==1)strcpy(x,"Excellent!");
else if(j==2)strcpy(x,"Nice work!");
else strcpy(x,"Keep up the good work!");}
else 
{if(j==0)strcpy(x,"No.Please try again.");
else if(j==1)strcpy(x,"Wrong.Try once more.");
else if(j==2)strcpy(x,"Don't give up!");
else strcpy(x,"Not correct.Keep trying.");}
printf("\n\"%s\"\n\n",x);
}
void main()
{ srand(time(NULL));
printf("欢迎使用计算机辅助教学系统!\n\n请选择要进行的任务(1~6):");
while(!(scanf("%d",&s) && s>=1 && s<=6))
printf("输入有误!请重新输入:");
switch(s)
{ case 1:
while(1)
{c1=rand()%10+1,c2=rand()%10+1,c=c1*c2;
printf("%d*%d=",c1,c2);
scanf("%lf",&p);
PJXT(PDXT(),1);}
break;
case 2:
while(1)
{c1=rand()%10+1,c2=rand()%10+1,c=c1*c2;
printf("%d*%d=",c1,c2);
scanf("%lf",&p);
PJXT(PDXT(),3);
if(i==3)
break;}
break;
case 3:
do{i++,c1=rand()%10+1,c2=rand()%10+1,c=c1*c2;
printf("%d*%d=",c1,c2);
scanf("%lf",&p);
PJXT(PDXT(),1);}
while(i!=10);
printf("你的总分为:%d分\n回答正确率为:%d%%\n",f,f);
break;
case 4:
do{i++,c1=rand()%10+1,c2=rand()%10+1;
SZYS();
printf("%d%c%d=",c1,F,c2);
scanf("%lf",&p);
PJXT(PDXT(),1);}
while(i!=10);
printf("你的总分为:%d分\n回答正确率为:%d%%\n",f,f);
break;
case 5:
do{i=0,f=0;
do{i++,c1=rand()%10+1,c2=rand()%10+1;
SZYS();
printf("%d%c%d=",c1,F,c2);
scanf("%lf",&p);
PJXT(PDXT(),1);}
while(i!=10);
printf("你的总分为:%d分\n回答正确率为:%d%%\n\n",f,f);
if (f<75)
printf("你的正确率低于75%%!请重新作答!\n\n");}
while(f<75);
break;
case 6:
do{i=0,f=0;
do{i++,c1=rand()%10+1,c2=rand()%10+1;
SZYS();
printf("%d%c%d=",c1,F,c2);
scanf("%lf",&p);
PJXT(PDXT(),2);}
while(i!=10);
printf("你的总分为:%d分\n回答正确率为:%d%%\n\n",f,f);
if (f<75)
printf("你的正确率低于75%%!请重新作答!\n\n");}
while(f<75);
break;
default:;}
}
阅读更多
想对作者说点什么? 我来说一句

FREERTOS API函数总结

2018年04月15日 554KB 下载

C复习讲稿

2011年12月30日 596KB 下载

pb-获取汉字首字母函数

2010年05月30日 3KB 下载

变步长simpson积分法

2013年12月30日 714B 下载

没有更多推荐了,返回首页

不良信息举报

刚学了函数..就要把开始的改编成函数形式的..到底什么是函数阿..?

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭