告别2021,希望2022能更上一层楼

//大家好,首先在这里祝大家元旦快乐,我目前是一位编程小白,想在这个平台记录自己的学习收获,希望大家喜欢!

#include<stdio.h>
#include<stdlib.h>
main()
{
    int num;//输入数字 
    int a,b,c,d;//用于运算 
    int i=0;//正确题数 
    int total=0;//总共题数 
    int t;//交换 
    int five;//第五个选项 
    int six;//第六个选项
    printf("     欢迎使用计算辅助练习系统!\n"); 
    printf(" \t1 加法运算5位数:\n");
    printf(" \t2 减法运算5位数:\n");
    printf(" \t3 乘法运算2位数:\n");
    printf(" \t4 除法运算2位数:\n");
    printf(" \t5 随机运算3位数:\n");
    printf(" \t6 三个数运算:\n");
    printf(" \t0 结束练习:\n");
n:    printf("当前第%d题,请输入数字:",total+1);
    scanf("%d",&num);
    switch(num)
    {
        case 1://加法运算 
            srand((unsigned)time(NULL));//随机播种函数 
            a=rand();
            b=rand();
            printf(" %d + %d = ? ",a,b);
            scanf("%d",&c);
            total++;
            if(c==a+b)
            {
                i++;
            }
            goto n;    
            break; 
        case 2://减法运算 
            srand((unsigned)time(NULL));
            a=rand();
            b=rand();
            if(a<b)
            {
                t=a;
                a=b;
                b=t;
            }
            printf(" %d - %d = ? ",a,b);
            scanf("%d",&c);
            total++;
            if(c==a-b)
            {
                i++;
            }
            goto n;
            break;
        case 3://乘法运算 
            srand((unsigned)time(NULL));
            a=rand()%99+1;
            b=rand()%99+1;
            printf(" %d * %d = ?",a,b);
            scanf("%d",&c);
            total++;
            if(c==a*b)
            {
                i++;
            }
            goto n;
            break;
        case 4://除法运算 
            srand((unsigned)time(NULL));
            a=rand()%99+1;
            b=rand()%99+1;
            c=a*b;
            printf(" %d / %d = ?",c,b);
            scanf("%d",&d);
            total++;
            if(d==c/b)
            {
                i++;
            }
            goto n;
            break;
        case 5://随机三位数 
            srand((unsigned)time(NULL));
            a=rand()%998+1;
            b=rand()%998+1;
            five=rand()%4;
            switch(five)
            {
                case 0:
                    printf(" %d + %d = ?",a,b);
                    scanf("%d",&c);
                    if(c==a+b)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
                case 1:
                    printf(" %d - %d = ?",a,b);
                    if(a<b)
                    {
                        t=a;
                        a=b;
                        b=t;
                    }
                    scanf("%d",&c);
                    if(c==a-b)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
                case 2:
                    printf(" %d * %d = ?",a,b);
                    scanf("%d",&c);
                    if(c==a*b)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
                default:
                    c=a*b;
                    printf(" %d / %d = ?",c,a);
                    scanf("%d",&d);
                    if(d==b)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
            }
        case 6://随机三个数 
            srand((unsigned)time(NULL));
            a=rand()%99+100;
            b=rand()%99+1;
            c=rand()%99+1;
            six=rand()%6;
            switch(six)
            {
                case 0:
                    printf(" %d + %d + %d = ?",a,b,c);
                    scanf("%d",&d);
                    if(d==a+b+c)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
                case 1:
                    printf(" %d + %d - %d = ?",a,b,c);
                    scanf("%d",&d);
                    if(d==a+b-c)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
                case 2:
                    printf(" %d - %d - %d = ?",a,b,c);
                    scanf("%d",&d);
                    if(d==a-b-c)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
                case 3:
                    printf(" %d - %d + %d = ?",a,b,c);
                    scanf("%d",&d);
                    if(d==a-b+c)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
                case 4:
                    printf(" %d * %d + %d = ?",a,b,c);
                    scanf("%d",&d);
                    if(d==a*b+c)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
                case 5:
                    printf(" %d * %d - %d = ?",a,b,c);
                    scanf("%d",&d);
                    if(d==a*b-c)
                    {
                        i++;
                    }
                    total++;
                    goto n;
                    break;
            }
        case 0://结束 
            break;
        default:
            printf("输入有误!\n");
            goto n;
            break;
    }
    printf("您一共做了%d题,对了%d题,得分%d分\n",total,i,i*100/total);
    if(total>=100)//做了一百题以上 
    {
        if(i*100/total>85)//正确率85%以上 
            printf("恭喜您今日任务达成!");
        else//正确率不足85% 
        {
            printf("今日任务未完成,请继续挑战!");
            goto n; 
        }    
    }    
    else//做了一百题以内 
    {
        printf("今日任务未完成,请继续挑战!");
        goto n; 
    }
}

//仿照着老师课上讲的程序自己写了一下,老师好像没有使用goto,但我用到了goto,还有需要改良的地方,2022,加油!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值