#include<iostream>
int main()
{
Action();
system("pause");
}
int Question(int n,int&result)
{
n = (n == 1) ? 2 : 4;
int type = rand() % n;
int x = rand() % 10, y = rand() % 10;
cout << x;
switch (type) {
case 0:cout << '+';result = x + y;;break;
case 1:cout << '-';result = x - y;;break;
case 2:cout << '*';result = x * y;;break;
case 3:cout << '/';result = x / y;;break;
default:return 0;
}
cout << y << "=";
return 1;
}
void Action()
{
char c;int hard;
int result,user_result;int num = 0;
cout << "现在开始(Y or N):" << endl;
cin >> c;
if (c == 'Y')
{
cout << "请输入难度(1 or 2):";
cin >> hard;
for (int i = 0;i < 10;i++)
{
Question(hard, result);
cin >> user_result;
cout << endl;
if (user_result == result) {
cout << "回答正确" ;
num++;
}
else cout << "回答错误";
if (i == 9)cout << endl << "您的得分为:";
else cout << ",下一题" << endl;
}
cout << num << endl;
}
else return;
}
C++实现运算计分
最新推荐文章于 2023-12-02 12:10:46 发布