四則運算生成器-個人項目1
阿新 • • 發佈:2017-09-27
pri warn style html question and switch secure 輸入
第一個個人項目四則運算生成器參考源代碼: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