随机产生1-10之间的随机正整数,进行四则运算,共十道题,在屏幕上产生算式:6*7=?若正确打印“Good!”如果错误打印“Wrong,Try Again!”但每个题只有三次重做机会,做对一题得十分,根据答题情况输出分数。
[输出]学生得分
1 随机数10个,加减乘除,做运算;
2 比较计算结果是否正确;
3 错误 有三次 重做机会;
4 最后累加结果输出成绩;
#include <iostream>
#include <ctime>
#include <cstdlib>
bool jisuan();
using namespace std;
int main()
{
int num=0;
for(int i=0; i<10; i++)
{
if(jisuan())
num++;
}
cout<<"最后得分为:"<<num*10;
return 0;
}
bool jisuan()
{
srand(time(0));
bool ban=true;
char ch;
double result=0,enresult=0;
double n1=rand()%9+1;
double n2=rand()%9+1;
int n3=rand()%4;
switch(n3)
{
case 0:
ch='+';
result=n1+n2;