四则运算改进版

#include<stdio.h>
int sum = 0;
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
struct NUM //一个运算符号整数存储
{
    int one;
    int two;
    int three;
}stu[400];
struct NUM1 // 一个运算符号真分数存储
{
    int first;//第一个数的分子
    int first1;//第一个数的分母
    int second;
    int second1;
    int result;
    int result1;
}stu1[400];
struct NUM2  //两个运算符号的存储
{
    int one;
    int two;
    int three;
    int result;
}stu2[400];
struct NUM3 //带括号的四则运算
{
    int one;
    int two;
    int three;
    int result;
}stu3[400];
int show();
void show1();
int integer();//整数
int fraction();//分数
int complex();//多符号数
int braces();//带括号的
int error();
void main()
{
    int a=1,b ;
    while (a == 1)
        {
            b = show();
            switch (b)
            {
                case 1: a = integer();
                    break;
                case 2: a = fraction();
                    break;
                case 3: a = complex();
                    break;
                case 4: a = braces();
                    break;
                case 5: a =error();
                    break;
                default:a =0;
                    break;
            }
        }
    show1();
}
int show()
{
    int a;
    printf("=========目录==========\n");
    printf("1.整数运算\n");
    printf("2.真分数运算\n");
    printf("3.多运算符的运算\n");
    printf("4.带括号的四则运算\n");
    printf("5.错题记录\n");
    printf("0.结束运算\n");
    printf("请输入你想进行运算的序号\n");
    scanf_s("%d", &a);
    return a;
}
void show1()
{
    printf("谢谢使用");
}
int integer()//整数
{
    int a, b, c, m;
    int s[10];
    for (int i = 0; i < 10; i++)
    {
        a = stu[sum].one = rand() % 10 + 1;
        b = stu[sum].two = rand() % 10 + 1;
        int n = rand() % 4 + 1;
        switch (n)
        {
        case 1: stu[sum].three = a + b;
            printf("%d+%d=\t", a, b); break;
        case 2: stu[sum].three = a - b;
            printf("%d-%d=\t", a, b); break;
        case 3: stu[sum].three = a*b;
            printf("%d*%d=\t", a, b); break;
        case 4: stu[sum].three = a /b;
            printf("%d/%d=\t", a, b); break;

        }
        sum = sum + 1;
    }
    printf("请输入上面十题的答案\n");
    for (int i = 0; i < 10; i++)
    {
        printf("%d.", i + 1);
        scanf_s("%d", &s[i]);
    }
    for (int i = 0; i < 10; i++)
    {
        if (s[i] == stu[sum - 9 + i].three)
        {
            printf("");
        }
        else {
            printf("第%d题错误,正确答案是%d   ", i + 1, stu[sum-9+i].three);
            if (i == 9)
            {
                printf("\n");
            }
        }
    }
    printf("继续请按1,结束请按任意键\n");
    scanf_s("%d", &m);
    if (m == 1)
        return 1;
    else
        return 0;
}
int fraction()//分数
{
    int a, b, c, d, m;
    int s[20];
    for (int i = 0; i < 10; i++)
    {
        a = stu1[sum1].first = rand() % 10 + 1;
        b = stu1[sum1].first1 = rand() % 10 + a;
        c = stu1[sum1].second = rand() % 10 + 1;
        d = stu1[sum1].second1 = rand() % 10 + c;
        int n= rand() % 4 + 1;
        switch (n)
        {
        case 1: stu1[sum1].result = a*d + c*b;
                stu1[sum1].result1 = b*d;
            printf("%d/%d+%d/%d=\t", a, b,c,d); break;
        case 2: stu1[sum1].result = a*d - c*b;
                stu1[sum1].result1 = b*d;
            printf("%d/%d-%d/%d=\t", a, b, c, d); break;
        case 3: stu1[sum1].result = a*c;
                stu1[sum1].result1 = b*d;
            printf("%d/%d*%d/%d=\t", a, b, c, d); break;
        case 4: stu1[sum1].result = a*d;
                stu1[sum1].result1 = b*c;
            printf("%d/%d/%d/%d=\t", a, b, c, d); break;

        }
        sum = sum + 1;
    }
    printf("请输入上面十题的答案\n");
    for (int i = 0; i < 10; i++)
    {
        printf("%d.分子", i + 1);
        scanf_s("%d", &s[i]);
        printf("%d.分母", i + 1);
        scanf_s("%d", &s[i+10]);
    }
    for (int i = 0; i < 10; i++)
    {
        if (s[i] == stu1[sum1 - 9 + i].result&&s[i+10] == stu1[sum1 - 9 + i].result1)
        {
            printf("");
        }
        else {
            printf("第%d题错误,正确答案是%d/%d  ", i + 1, stu1[sum1 - 9 + i].result, stu1[sum1 - 9 + i].result1);
            if (i == 9)
            {
                printf("\n");
            }
        }
    }
    printf("继续请按1,结束请按任意键\n");
    scanf_s("%d", &m);
    if (m == 1)
        return 1;
    else
        return 0;
}
int complex()//多符号数
{
    int a, b, c, m;
    int s[10];
    for (int i = 0; i < 10; i++)
    {
        a = stu2[sum2].one = rand() % 10 + 1;
        b = stu2[sum2].two = rand() % 10 + 1;
        c = stu2[sum2].three = rand() % 10 + 1;
        int n = rand() % 4 + 1;
        switch (n)
        {
        case 1: stu2[sum2].result = (a*b)+ c;
            printf("%d*%d+%d=\t", a, b, c); break;
        case 2: stu2[sum2].result = a + (b * c);
            printf("%d+%d*%d=\t", a, b, c); break;
        case 3: stu2[sum2].result = (a*b) - c;
            printf("%d*%d-%d=\t", a, b, c); break;
        case 4: stu2[sum2].result = a - (b * c);
            printf("%d-%d*%d=\t", a, b, c); break;

        }
        sum = sum + 1;
    }
    printf("请输入上面十题的答案\n");
    for (int i = 0; i < 10; i++)
    {
        printf("%d.", i + 1);
        scanf_s("%d", &s[i]);
    }
    for (int i = 0; i < 10; i++)
    {
        if (s[i] == stu2[sum2-9+i].result)
        {
            printf("");
        }
        else {
            printf("第%d题错误,正确答案是%d  ", i + 1, stu2[i].result);
    
            if (i == 9)
            {
                printf("\n");
            }
        }
    }
    printf("继续请按1,结束请按任意键\n");
    scanf_s("%d", &m);
    if (m == 1)
        return 1;
    else
        return 0;
}
int braces()//带括号的
{
    int a, b, c, m;
    int s[10];
    for (int i = 0; i < 10; i++)
    {
        a = stu3[sum3].one = rand() % 10 + 1;
        b = stu3[sum3].two = rand() % 10 + 1;
        c = stu3[sum3].three = rand() % 10 + 1;
        int n = rand() % 4 + 1;
        switch (n)
        {
        case 1: stu3[sum3].result = a*(b + c);
            printf("%d*(%d+%d)=\t", a, b, c); break;
        case 2: stu3[sum3].result = (a - b) * c;
            printf("(%d-%d)*%d=\t", a, b, c); break;
        case 3: stu3[sum3].result = a/(b - c);
            printf("%d/(%d-%d)=\t", a, b, c); break;
        case 4: stu3[sum3].result = (a + b )/ c;
            printf("(%d-%d)/%d=\t", a, b, c); break;

        }
        sum = sum + 1;
    }
    printf("请输入上面十题的答案\n");
    for (int i = 0; i < 10; i++)
    {
        printf("%d.", i + 1);
        scanf_s("%d", &s[i]);
    }
    for (int i = 0; i < 10; i++)
    {
        if (s[i] == stu3[sum3 - 9 + i].result)
        {
            printf("");
        }
        else {
            printf("第%d题错误,正确答案是%d  ", i + 1, stu2[i].result);
        
            if (i == 9)
            {
                printf("\n");
            }
        }
    }
    printf("继续请按1,结束请按任意键\n");
    scanf_s("%d", &m);
    if (m == 1)
        return 1;
    else
        return 0;
}

posted @ 2016-03-16 09:41  会飛的虾  阅读(169)  评论(2编辑  收藏  举报