码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算生成器-个人项目1

时间:2017-09-27 15:24:28      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:链接   getch   etc   logs   题目   include   stdio.h   stdin   开始   

第一个个人项目四则运算生成器参考源代码:https://zhidao.baidu.com/question/532330836.html?qbl=relate_question_0&word=%D3%C3C%D3%EF%D1%D4%CA%B5%CF%D6%CB%C4%D4%F2%D4%CB%CB%E3%C9%FA%B3%C9%C6%F7

改了一点点功能,运行有错误,也改过来了。

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include<conio.h>
int test(int number)
{
    int counter = 0;
    int answer = 0;
    int result = 0;
    int m = 0;
    int n = 0;
    char op = 0;

    while (number--)
    {
        m = rand() % 10;
        n = rand() % 10;
        op = rand() % 4;

        switch (op)
        {
        case 0:
            op = +;
            answer = m + n;
            break;
        case 1:
            op = -;
            answer = m - n;
            break;
        case 2:
            op = *;
            answer = m*n;
            break;
        case 3:
            ++n;
            op = /;
            answer = m / n;
            break;
        default:
            break;
        }

        printf("题目:");
        printf("%d %c %d = ", m, op, n);
        while (scanf("%d", &result) != 1)
            fflush(stdin);
        if (answer == result)
            ++counter;
    }

    return counter;
}

int main()
{
    int number;
    srand(time(NULL));

    printf("开始做题\n");
    printf("请输入题目数:");
    while (scanf("%d", &number) != 1)
        fflush(stdin);
    printf("答题结束,总共答对%d道题目\n", test(number));
    return 0;

    _getch();
}

已上传到github,链接:https://github.com/FawnRain/Four-Arithmetic-Operations

四则运算生成器-个人项目1

标签:链接   getch   etc   logs   题目   include   stdio.h   stdin   开始   

原文地址:http://www.cnblogs.com/gai-blog/p/7601812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!