周周Amor

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
这个作业属于哪个课程 https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/
这个作业要求在哪里 https://edu.cnblogs.com/campus/ahgc/AHPU-SE-19/homework/11376
这个作业的目标 能自动生成小学四则运算题目的程序,然后在此基础上扩展完成额外的题目
学号 3190704127

代码如下:

include<stdio.h>

include<stdlib.h>

include<windows.h>

include<time.h>

int menu()//选择菜单
{
int choice;
system("cls");
printf("\n\t算术题选择\n\n");
printf("\t~【1】加法运算题~\n");
printf("\t~【2】减法运算题~\n");
printf("\t~【3】乘法运算题~\n");
printf("\t~【4】除法运算题~\n");
printf("\t~【0】退出选择~~~\n");
printf("\t\t请输入一个数<1~4>\n");
scanf("%d",&choice);
while(choice<0||choice>4)
{
printf("请重新选择:");
scanf("%d",&choice);
}
return choice;
}

void Start_Count(int n)
{
int sum=0;//总题数
int correct=0;//正确数
int a,b;//两个操作数
int ans;//记录结果
char temp;
system("cls");
while(1)
{
srand(time(NULL));
a=rand()%50;
b=rand()%50;
while(n4 && a%b!=0)
{
a=rand()%50;
b=rand()%50;
}
if(n
1)//加法
{
printf("%d + %d = ",a,b);
scanf("%d",&ans);
if(ans == a+b)
{
correct++;
}
}
if(n2)//减法
{
printf("%d - %d = ",a,b);
scanf("%d",&ans);
if(ans == a-b)
{
correct++;
}
}
if(n
3)//乘法
{
printf("%d * %d = ",a,b);
scanf("%d",&ans);
if(ans == ab)
{
correct++;
}
}
if(n4)//除法
{
printf("%d / %d = ",a,b);
scanf("%d",&ans);
if(ans == a/b)
{
correct++;
}
}
sum++;
printf("是否继续?(Y/N)😊;
fflush(stdin);
scanf("%c",&temp);
if(temp
'n'||temp=='N')
{
break;
}
}
printf("一共回答了%d题\n",sum);
printf("回答对了%d题\n",correct);
printf("正确率为%.2f%%\n",correct
100.0/sum);
system("pause");
}

int main()
{
int choice=menu();
Start_Count(choice);
return 0;
}

posted on 2020-10-27 23:36  周周Amor  阅读(77)  评论(0编辑  收藏  举报