• c语言寒假大作战04


    这个作业属于哪个课程 班级链接
    这个作业的要求 作业链接
    这个作业的目标 使用Switch语句来完成菜单程序
    参考文献 百度百科

    设计思路和遇到的问题

    1.根据前两次作业的基础在进行运算
    2.输出格式总是不正确

    程序结果截图




    程序代码

    include<stdio.h>

    include <stdlib.h>

    include <time.h>

    void menu(){
    printf("操作列表: 1)一年级 2)二年级 3)三年级 4)帮助 5)退出程序 请输入操作> ");
    }
    void help(){
    printf("帮助信息 您需要输入命令代号来进行操作, 且 一年级题目为不超过十位的加减法; 二年级题目为不超过百位的乘除法; 三年级题目为不超过百位的加减乘除混合题目. ");
    }
    void error(){
    printf("Error!!! 错误操作指令, 请重新输入 ");
    }
    void firstgrade(){
    srand(time(NULL));
    int a,b,c,i;
    char f[2]={'+','-'},fl;
    printf("现在是一年级题目: 请输入生成题目的个数:");
    scanf("%d",&i);
    for(;i>0;i--){
    a=rand()%101;
    b=rand()%101;
    fl=f[rand()%2];
    if(fl'+')
    c=a+b;
    else c=a-b;
    printf("%d %c %d = %2d ",a,fl,b,c);
    }
    printf(" ");
    }
    void secondgrade(){
    srand(time(NULL));
    int a,b,i;
    double c;
    char f[2]={'*','/'},fl;
    printf("现在是二年级题目: 请输入生成题目的个数:");
    scanf("%d",&i);
    for(;i>0;i--){
    a=rand()%101;
    b=rand()%101;
    fl=f[rand()%2];
    if(fl
    '/'&&b0)b=rand()%100+1;
    if(fl
    '/')c=a1.0/b;
    else c=a
    b;
    printf("%d %c %d = %2g ",a,fl,b,c);
    }
    printf(" ");
    }
    void thirdgrade(){
    srand(time(NULL));
    int a,b,i,c,n,q;
    double m;
    char f[4]={'','/','+','-'},d,e;
    printf("现在是三年级题目: 请输入生成题目的个数:");
    scanf("%d",&i);
    for(;i>0;i--){
    a=rand()%101;
    d=f[rand()%4];
    b=rand()%101;
    if(d'/'&&b0) b=rand()%100+1;
    e=f[rand()%4];
    c=rand()%101;
    if(e'/'&&c0) c=rand()%100+1;
    switch (d)
    {
    case '+':n=1;break;
    case '-':n=2;break;
    case '
    ':n=3;break;
    case '/':n=4;break;
    }
    switch (e)
    {
    case '+':q=1;break;
    case '-':q=2;break;
    case '':q=3;break;
    case '/':q=4;break;
    }
    switch (n)
    {
    case 1:
    if(q1)
    m=a+b+c;
    else if(q
    2)
    m=a+b-c;
    else if(q==3)
    m=a+b
    c;
    else m =a+b1.0/c;
    break;
    case 2:
    if(q1)
    m=a-b+c;
    else if(q
    2)
    m=a-b-c;
    else if(q==3)
    m=a-b
    c;
    else m =a-b1.0/c;
    break;
    case 3:
    if(q==1)
    m=a
    b+c;
    else if(q2)
    m=a*b-c;
    else if(q
    3)
    m=abc;
    else m =ab1.0/c;
    break;
    case 4:
    if(q1)
    m=a*1.0/b+c;
    else if(q
    2)
    m=a1.0/b-c;
    else if(q==3)
    m=a
    1.0/bc;
    else m =a
    1.0/b/c;
    break;
    }
    printf("%2d %c %2d %c %2d = %2g ",a,d,b,e,c,m);
    }
    printf(" ");
    }

    int main()
    {
    int a;
    printf("========== 口算生成器 ========== 欢迎使用口算生成器 : ");
    help();
    menu();
    do{
    scanf("%d",&a);
    printf("< 执行操作 > ");
    switch (a) {
    case 1:firstgrade();break;
    case 2:secondgrade();break;
    case 3:thirdgrade();break;
    case 4:help(); break;
    case 5:printf("程序结束, 欢迎下次使用 任意键结束…… ");break;
    default:error();break;
    }
    if(a!=5)menu();
    }while(a!=5);
    return 0;
    }

    Gitee上传截图与链接

  • 相关阅读:
    ubuntu14.04 Cannot find OpenSSL's <evp.h>
    git 常用命令
    Python3常用模块的安装
    Centos7 安装配置优化mysql(mariadb分支)
    Centos7 编译安装python3
    Centos6.5搭建git远程仓库
    年轻
    springboot 报错Field XXX required a bean of type XXX that could not be found.
    springboot 启动报错[classpath:/application.yml] but snakeyaml was not found on the classpath
    idea 使用点击maven clean/install或maven其他命令失败,显示:乱码+archetypeCatalog=internal
  • 原文地址:https://www.cnblogs.com/ztxztx/p/12442032.html
Copyright © 2020-2023  润新知