四则运算第一阶段

源代码:

 #include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
float x, y;
int a, b, i;
srand(time(NULL));
float k;
float d;
float answer[10];
int zq = 0;
int cw = 0;
for (i = 0; i<10; i++)
{
x = rand() % 100;
y = rand() % 100;
a = rand() % 4;
switch (a)
{
case 0:
cout << i + 1 << ".  " << x << "+" << y << "   ";
answer[i + 1] = x + y;
break;
case 1:
cout << i + 1 << ".  " << x << "-" << y << "   ";
answer[i + 1] = x - y;
break;
case 2:
cout << i + 1 << ".  " << x << "*" << y << "   ";
answer[i + 1] = x*y;
break;
case 3:
if (y != 0)
{
cout << i + 1 << ".  " << x << "÷" << y << "   ";
answer[i + 1] = (float)x / y;
}
else
{
i = i - 1;
}
break;
}
if ((i + 1) % 3 == 0)
{
for (int c = 0; c <= 1; c++)
{
cout << endl;
}
}
if ((i + 1) == 10)
{
cout << endl;
}
}
for (i = 1; i <= 10; i++)
{
cout << "请答题:" << endl;
cout << i << ". ";
cin >> d;
if (d == answer[i])
{
cout << "回答正确!!" << endl;
cout << endl;
zq = zq + 1;
}
else
{
cout << "回答错误,正确答案为:  " << answer[i] << endl;
cout << endl;
cw = cw + 1;
}
}
k = (float)zq / 10;
cout << "答对数为:  "  << zq << "个" << endl;
cout << "答错数为:  "  << cw << "个" << endl;
cout << "正确率为:  "  << k << endl;
return 0;
}

  结果

posted @ 2018-11-11 21:08  吃牛肉  阅读(106)  评论(0编辑  收藏  举报