C语言寒假大作战03

这个作业属于那个课程 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/10269
这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/10269
这个作业的目标是 熟悉用函数和switch语句编程口算题菜单,还有随机数rand的使用
作业正文 随机数的使用
参考文献 https://www.runoob.com/cprogramming/c-function-rand.html

2.2.2设计思路和遇到的问题

设计思路:和前面的第二次作业相似,但需要使用随机rand函数,添加进去即可。在开头多弄几个函数。
遇到的问题:开始不知道怎么随机得到加减乘除,那数是怎么生成的,通过资料查询就明白了点,但还不是特别理解。

2.2.3程序结果截图

2.2.4程序代码

#include <stdio.h>
#include<stdlib.h>
#include<time.h> 
void menu();
void help();
void error();
void operation_1();void one();
void operation_2();void two();
void operation_3();void three();

int main()
{
    int m;
    printf("========== 口算生成器 ==========\n欢迎使用口算生成器 :\n希望早日开学\n");
    printf("\n");
    help();
    while(1)
    {
        menu();
        scanf("%d",&m);
        switch(m)
        {
            case 1:operation_1();break;
            case 2:operation_2();break;
            case 3:operation_3();break;
            case 4:help();break;
        }
        printf("\n");
        if(m==5) break;
        if(m>5||m<1) error();
    }
    return 0;
}
void help()
{
    printf("帮助信息\n您需要输入命令代号来进行操作, 且\n");
    printf("一年级题目为不超过十位的加减法;\n二年级题目为不超过百位的乘除法;\n""三年级题目为不超过百位的加减乘除混合题目.\n");
    printf("\n");
}
void menu()
{
    printf("操作列表:\n1)一年级    2)二年级    3)三年级\n4)帮助      5)退出程序\n请输入代号:");
}
void error()
{
    printf("错误程序,请重新输入正确数值。");
    printf("\n");
 } 
 void operation_1()
 {
    printf("请输入题目个数>");
    one();
 }
  void operation_2()
 {
    printf("请输入题目个数>");
    two();
 }
  void operation_3()
 {
    printf("请输入题目个数>");
    three();
 }
  void one()
 {
    int x,a,b,c;
    scanf("%d",&x);
    printf("现在是一年级题目:\n"); 
    srand((unsigned)time(NULL));
    for(int i=1;i<=x;i++)
    {
        a=rand()%10;
        b=rand()%10;
        c=rand()%2;
        switch(c){
        	case 0:printf("%d + %d = ___",a,b);break;
        	default: printf("%d - %d = ___",a,b);
		}
		printf("\n");
     } 
 } 
 void two()
 {
    int x,a,b,c;
    scanf("%d",&x);
    printf("现在是二年级题目:\n"); 
    srand((unsigned)time(NULL));
    for(int i=1;i<=x;i++)
    {
        a=rand()%100;
        b=rand()%100;
        c=rand()%4;
        if(c==0)
        printf("%3d * %3d = ___",a,b);
        else
        printf("%3d / %3d = ___",a,b);
        printf("\n");
     } 
 }
 void three()
 {
    int x,a,b,c;
    scanf("%d",&x); 
    printf("现在是三年级题目:\n"); 
    srand((unsigned)time(NULL));
    for(int i=1;i<=x;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");
     }
 }

2.2.5Gitee上传截图与链接

https://gitee.com/deng_zhi_zhu/dashboard

posted @ 2020-02-11 11:21  邓志卓  阅读(105)  评论(0编辑  收藏  举报