任务实验七

源代码、

点击查看代码
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;

int main()
{
    srand(time(0));
    int right = 0;
    const int total = 10;
    for(int i = 0; i < total; i++)
    {
        int a, b, op;
        int ans;
        op = rand() % 4;
        if(op == 0)
        {
            a = rand() % 10 + 1;
            b = rand() % 10 + 1;
            ans = a + b;
            cout << a << " + " << b << " = ";
        }
        else if(op == 1)
        {
            a = rand() % 10 + 1;
            b = rand() % a + 1;
            ans = a - b;
            cout << a << " - " << b << " = ";
        }
        else if(op == 2)
        {
            a = rand() % 10 + 1;
            b = rand() % 10 + 1;
            ans = a * b;
            cout << a << " * " << b << " = ";
        }
        else
        {
            b = rand() % 10 + 1;
            int k = rand() % 10 + 1;
            a = k * b;
            ans = k;
            cout << a << " / " << b << " = ";
        }
        int user;
        cin >> user;
        if(user == ans)
        {
            right++;
        }
    }
    double rate = 100.0 * right / total;
    cout << fixed << setprecision(2) << "正确率:" << rate << "%" << endl;
    return 0;
}
![image](https://img2024.cnblogs.com/blog/3861693/202610/3861693-20261022150053922-905748146.png)
posted @ 2026-10-22 15:01  d111kkk  阅读(2)  评论(0)    收藏  举报