1,221
社区成员
发帖
与我相关
我的任务
分享
#include <ctime> // For time()
#include <cstdlib> // For srand() and rand()
#include <iostream>
#include <windows.h>
using namespace std;
auto method()
{
int v1 = abs(rand() % 10 - 6);//加0减1乘2除3
return v1;
}
int main()
{
srand(time(NULL));
while (true)
{
int v2 = rand() % 100 + rand() % 100;//两位数 三位数的随机数
int v3 = rand() % 100 + rand() % 100;// ``
if (method()==0)
{
int answer;
cout << v2 << " + " << v3 << endl;
cin >> answer;
if (answer == v2 + v3) { cout << "回答正确" << endl; }
else { cout << "回答错误" << endl; }
}
else if (method() == 1 && v2 > v3)
{
cout << v2 << " - " << v3 << endl;
int answer;
cin >> answer;
if (answer == v2 - v3) { cout << "回答正确" << endl; }
else { cout << "回答错误" << endl; }
}
else if (method() == 2)
{
cout << v2 << " x " << v3 << endl;
int answer;
cin >> answer;
if (answer == v2 * v3) { cout << "回答正确" << endl; }
else { cout << "回答错误" << endl; }
}
else if (method() == 3 && v2 > v3)
{
cout << v2 << " ÷ " << v3 << endl;
int answer;
cin >> answer;
if (answer == v2 / v3) { cout << "回答正确" << endl; }
else { cout << "回答错误" << endl; }
}
else
{
continue;
}
Sleep(300);
}
}
大致思路就是这个了,剩下的需要你自己看着调整一下,毕竟是小学生么。