码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算第一阶段

时间:2018-11-11 23:28:28      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:rand   stream   for   bubuko   分享   switch   正确答案   ++   ==   

源代码:

 #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;
}

  结果

四则运算第一阶段

标签:rand   stream   for   bubuko   分享   switch   正确答案   ++   ==   

原文地址:https://www.cnblogs.com/dongdongdongdong/p/9943565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!