该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
有高人看看下面的program
#include
#define HOW 10
using namespace std;
char get_oper(int n)
{
switch(n)
{
case 0:return '+';
case 1:return '-';
case 2:return '*';
case 3:return '/';
}
return'*';
}
int main()
{
int num1=0,num2=0,count=0;
double user_answer=0;
float right_answer=0;
int operators=0; //0:+ 1:- 2:* 3:/
int sum = 0;
char cont = 'n';
cout<
cout<
cout<
cout<
cout<
cout<
do
{
for(int i=1;i<=HOW;i++)
{
//randamly create the numbers and operators.
num1=rand()%100 + 1;
num2=rand()%100 + 1;
operators=rand()%4;
if(operators==3)num1=num2*(rand()%100);
//create the questions and wait the user to calculate the answers
cout<
cin>>user_answer;
//give the answers and let the user to check the result
switch(operators)
{
case 0:right_answer=num1+num2;break;
case 1:right_answer=num1-num2;break;
case 2:right_answer=num1*num2;break;
case 3:right_answer=num1/num2;
}
//examin the user's answers
if(right_answer==user_answer)
{
cout<
count++;
sum = sum + 10;
}
else {
cout<
sum = sum - 5; }
}
//output the total marks for the user
cout<
cout<
cout<
cout<
cout<< "Do you want to keep playing?"<
cout<< "Type 'y' for yes and 'n' for no:";
cin>> cont;
}
while (cont=='y');
system ("pause");
return 0;
}
如果出来的除法答案是无限循环小数怎么办啊?输入什么答案都是错呢!
听别人说是需要加精度的,可是怎么加? 给个例子啊!