【2-3-3】
乘法如图【2-3-4】所示
【2-3-4】
运行结果如图【2-3-5】所示
【2-3-5】
3.3 源程序清单(关键代码)
#define _CRT_SECURE_NO_WARNINGS #include
srand(time(NULL)); int type; int exitFlag = 1; while (exitFlag) {
while (1) {
system(\
cout << \请输入编号选择题目类型:\\n1.加法\\n2.减法
\\n3.乘法\\n你的选择:\
endl;
break; }
cout << \请输入需要的题目数目:\int nQues; cin >> nQues; int nCorr = 0; system(\
for (int i = 0; i < nQues; ++i) {
int p1, p2, ans; p1 = rand() % 100; switch (type) { case 1:
p2 = rand() % 100;
cout << \进度:\cin >> ans; if (ans == p1 + p2) { } else
cout << \正确答案是:\cout << \nCorr++; cin >> type;
if (type <= 3 && type >= 1) break;
<< p1 << \
case 2:
p2 = rand() % (p1 + 1);
cout << \进度:\
<< p1 << \
endl;
endl;
} break; break;
p1 = rand() % 20; p2 = rand() % 20;
cout << \进度:\cin >> ans; if (ans == p1 * p2) { } else
cout << \正确答案是:\cout << \nCorr++; case 3:
cin >> ans; if (ans == p1 - p2) { } else
cout << \正确答案是:\cout << \nCorr++;
<< p1 << \