C语言寒假大作战03

|这个作业属于哪个课程|https://edu.cnblogs.com/campus/zswxy/CTS2019-4/homework/10269|
|------|------|------|
|这个作业要求在哪|https://edu.cnblogs.com/campus/zswxy/CTS2019-4/homework/10269|
|这个作业的目标|使用上次作业的菜单框架,并在其基础上增加各年级题目操作函数|
|作业正文|https://i-beta.cnblogs.com/posts/edit|
|其他参考文献|参考资料随机数rand、百度|
1设计思路和遇到的问题
思路:在第二次作业的基础上进行另外的处理,因为随机是个新的难点,所以就看了最后的参考资料,才知道rand()函数该怎么来写,怎么来用;
问题:对于rand函数的使用还是不熟悉,理解不透彻。
2程序结果截图

3程序代码

include <stdio.h>

include<stdlib.h>

include<time.h>

void menu();
void help();
void error();
void operation_1();void one_1();
void operation_2();void two_1();
void operation_3();void three_1();
int main()
{
int n;
printf("========== 口算生成器 ====\n");
printf("欢迎使用口算生成器 :\n");
printf("小学生必备神器\n");
printf("\n");
help();
while(1)
{
menu();
scanf("%d",&n);
switch(n)
{
case 1:operation_1();break;
case 2:operation_2();break;
case 3:operation_3();break;
case 4:help();break;
}
printf("\n");
if(n
5) break;
if(n>5||n<1) error();
}
return 0;
}
void help()
{
printf("帮助信息\n");
printf("您需要输入命令代号来进行操作\n");
printf("一年级题目为不超过十位的加减法\n");
printf("二年级题目为不超过百位的乘除法\n");
printf("三年级题目为不超过百位的加减乘除混合题目\n");
printf("\n");
}
void menu()
{
printf("操作列表:\n1)一年级 2)二年级 3)三年级\n");
printf("4)帮助 5)退出程序\n请输入代号:");
}
void error()
{
printf("哦买噶 错啦 请重新输入 ");
printf("\n");
printf("\n");
}
void operation_1()
{
printf("请输入题目数量>");
one_1();
}
void operation_2()
{
printf("请输入题目数量>");
two_1();
}
void operation_3()
{
printf("请输入题目数量>");
three_1();
}
void one_1()
{
int n,a,b,c;
scanf("%d",&n);
printf("一年级题目如下:\n");
srand((unsigned)time(NULL));
for(int i=1;i<=n;i++)
{
a=rand()%10+1;
b=rand()%10+1;
c=rand()%2;
if(c
0)
printf("%2d + %2d = ___",a,b);
else
printf("%2d - %2d = ___",a,b);
printf("\n");
}
}
void two_1()
{
int n,a,b,c;
scanf("%d",&n);
printf("二年级题目如下:\n");
srand((unsigned)time(NULL));
for(int i=1;i<=n;i++)
{
a=rand()%100;
b=rand()%100;
c=rand()%2;
if(c
0)
printf("%3d * %3d = ___",a,b);
else
printf("%3d / %3d = ___",a,b);
printf("\n");
}
}
void three_1()
{
int n,a,b,c;
scanf("%d",&n);
printf("三年级题目如下:\n");
srand((unsigned)time(NULL));
for(int i=1;i<=n;i++)
{
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch(c)
{
case 0:printf("%3d + %3d = ___",a,b);break;
case 1:printf("%3d - %3d = ___",a,b);break;
case 2:printf("%3d * %3d = ___",a,b);break;
case 3:printf("%3d / %3d = ___",a,b);break;
}
printf("\n");
}
}
4Gitee上传截图与链接

posted on 2020-02-12 15:12  等风来咯  阅读(140)  评论(0编辑  收藏  举报

导航