菜鸟的第一步

mac2024-03-11  30

菜鸟的第一步

小学生计算器(对入口参数的完善还未完整)

#include<stdio.h> #include<stdlib.h> #include<time.h> #define RANDOM(a,b) (rand()%( (b+1)-(a) )+(a) ) int suiji(void); int total (void); void start(void); void shape1(void); void shape2(void); void shape3(void); void shape4(void); void shape5(void); void judge_1(int reply, int produce, int flag, int *flag_one, int *yz_1, int *yz_1_1); void judge_2(int reply, int produce, int *flag, int *yz_2, int *counter); void judge_3(int reply_3, int produce_3, int *counter_3); void judge_4(int reply_4, int produce_4, int *counter_4); void judge_5(int reply_5, int produce_5, int *counter_5); void judge_5_5(int rate_5, int *flag_5); void JUDGE(int ret); int main() { int choose, firstflag=1; int ret; while(firstflag) { start(); ret=scanf("%d", &choose); JUDGE(ret); switch(choose) { case 1: shape1(); break; case 2: shape2(); break; case 3: shape3(); break; case 4: shape4(); break; case 5: shape5(); break; case 0: firstflag= 0; } system("pause"); } return 0; } void start(void) { system("cls"); srand(time(NULL)); printf("1、随机产生 1-10 之间正整数,出乘法问题,直到学生答对为止\t\t\ttesk 1\n"); printf("2、在任务 1 基础上,当学生答错时,最多给三次机会\t\t\t\ttesk 2\n"); printf("3、在任务 1 基础上,连做 10 道乘法题,不给机会重做,统计总分、正确率\t\ttesk 3\n"); printf("4、在任务 3 基础上,随机产生 10 道四则运算题,不给机会重做,统计总分、正确率\ttesk 4\n"); printf("5、在任务 4 基础上,若回答正确率低于 75%,则再做 10 道题,直到正确率高于75%&为止\ttesk 5\n"); printf("退出----------------------------------------------------------------------------exit 0\n"); } void shape1(void) { int a[1000]={0}; int produce, reply, flag=1, i; int flag_one=0; int yz_1=0; int yz_1_1=0; int ret; while(flag) { for(i=0; i<2; i++) { a[i]=suiji(); } produce= a[0]*a[1]; ONE: printf("%d*%d= ?\n", a[0], a[1], produce); printf("please input your answer:"); ret= scanf("%d", &reply); JUDGE(ret); judge_1(reply, produce, flag, &flag_one, &yz_1, &yz_1_1); if(yz_1==1 && yz_1_1==0) goto ONE; if(yz_1_1==1) break; } } void shape2(void) { int a[1000]={0}; int i; int reply, produce, counter, flag, yz_2; flag= 1, counter= 1, yz_2=0; while(flag) { for(i=0; i<2; i++) { a[i]=suiji(); } produce= a[0]*a[1]; printf("%d*%d= ?\n", a[0], a[1], produce); printf("please input your answer:"); scanf("%d", &reply); judge_2(reply, produce, &flag, &yz_2, &counter); if(yz_2==1) break; } } void shape3(void) { int a[1000]={0}; int i, t; int counter_3, reply_3, rate_3, produce_3; int ret; counter_3=0; for(t=0; t<10; t++) { for(i=0; i<2; i++) { a[i]=suiji(); } produce_3=a[0]*a[1]; printf("%d*%d= ?\n", a[0], a[1], produce_3); printf("please input your answer:"); ret= scanf("%d", &reply_3); JUDGE(ret); judge_3(reply_3, produce_3, &counter_3); } rate_3= counter_3; printf("%d %d%%\n", counter_3, rate_3); } void shape4(void) { int a[1000]={0}; int t, i, j; int counter_4, produce_4, reply_4, rate_4; char op, ops[] = { '+', '-', '*', '/' }; int ret; counter_4=0; for(t=0; t<10; t++) { for(i=0; i<2; i++) { FOUR: a[i]=suiji(); if(a[i]%2==0) goto FOUR; } op= ops[RANDOM(0,3)]; if(op=='+') produce_4=a[0]+a[1]; else if(op=='-') { if(a[0]<a[1]) goto FOUR; else produce_4=a[0]-a[1]; } else if(op=='*') produce_4=a[0]*a[1]; else if(op=='/') { j=a[0]%a[1]; if(a[0]<a[1] || j!=0) goto FOUR; else produce_4=a[0]/a[1]; } printf("%d%c%d= ?\n", a[0], op, a[1], produce_4); printf("please input your answer:"); ret=scanf("%d", &reply_4); JUDGE(ret); judge_4(reply_4, produce_4, &counter_4); } rate_4= counter_4; printf("%d %d%%\n", counter_4, rate_4); } void shape5(void) { int a[1000]={0}; int i, t, j; int counter_5, flag_5, produce_5, rate_5, reply_5; char op, ops[] = { '+', '-', '*', '/' }; int ret; counter_5=0; flag_5= 1; while(flag_5) { for(t=0; t<10; t++) { for(i=0; i<2; i++) { FIVE: a[i]=suiji(); if(a[i]%2==0) goto FIVE; } op= ops[RANDOM(0,3)]; if(op=='+') produce_5=a[0]+a[1]; else if(op=='-') { if(a[0]<a[1]) goto FIVE; produce_5=a[0]-a[1]; } else if(op=='*') produce_5=a[0]*a[1]; else if(op=='/') { j=a[0]%a[1]; if(a[0]<a[1] || j!=0) goto FIVE; else produce_5=a[0]/a[1]; } printf("%d%c%d= ?\n", a[0], op, a[1], produce_5); printf("please input your answer:"); ret=scanf("%d", &reply_5); JUDGE(ret); judge_5(reply_5, produce_5, &counter_5); } rate_5= counter_5; printf("%d %d%%\n", counter_5, rate_5); judge_5_5(rate_5, &flag_5); } } int suiji(void) { int a; a=rand()%10+1; return a; } int total(void) { static int a=0; a+=10; return a; } void judge_1(int reply, int produce, int flag, int *flag_one, int *yz_1, int *yz_1_1) { if(reply==produce && *flag_one==0) { printf("Right\n"); } if(reply==produce && *flag_one!=0) { printf("Right\n"); *yz_1_1=1; } if(reply!=produce) { printf("Wrong!Please try again\n"); *flag_one=1; *yz_1=1; } } void judge_2(int reply, int produce, int *flag, int *yz_2, int *counter) { if(reply==produce) { printf("Right\n"); } else { if(*counter>2) { printf("Wrong! You have tried three times! Test over!\n"); *flag=0; *yz_2=1; } else { printf("Wrong!Please try again\n"); *counter=*counter+1; } } } void judge_3(int reply_3, int produce_3, int *counter_3) { if(reply_3==produce_3) { printf("Right!\n"); *counter_3=total(); } else { printf("Wrong!\n"); } } void judge_4(int reply_4, int produce_4, int *counter_4) { if(reply_4==produce_4) { printf("Right!\n"); *counter_4= total(); } else { printf("Wrong!\n"); } } void judge_5(int reply_5, int produce_5, int *counter_5) { if(reply_5==produce_5) { printf("Right!\n"); *counter_5= total(); } else { printf("Wrong!\n"); } } void judge_5_5(int rate_5, int *flag_5) { if(rate_5>75) { printf("-----------------------------------------Good!\tOver!\n"); flag_5= 0; } else { printf("-----------------------------------------You are lose!\tTry again!\n"); system("pause"); } } void JUDGE(int ret) { if(ret!=1) { printf("Input dada quantity or format error!\n"); fflush(stdin); } }
最新回复(0)