四则运算生成器-个人项目1
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了四则运算生成器-个人项目1相关的知识,希望对你有一定的参考价值。
第一个个人项目四则运算生成器参考源代码: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的主要内容,如果未能解决你的问题,请参考以下文章