如果编码错误,我想让他自动跳过重新随机刷一次数字,怎么让它回去?
刚学,说不清楚,下面出代码,其中除数我要求 (b==0 && a/b!=0)a/b!=0的意思好像是不被整除的意思吧?难道我理解错误,看编码~~~===============================================================================================================
#include "iostream.h"
#include "stdlib.h"
#include "time.h"
int main()
{
int a,b;
float numOfQues=0,numOfRight=0;
char inquiry;
srand(time(NULL));
cout<<"欢迎来计算两位数的加减法运算!"<<endl;
do
{
int temp=3;//为了测试除数正确性,特意改成3的
a=rand()%10;//产生一个10以内的随机数
b=rand()%10;//产生一个10以内的随机数
switch (temp)
{
case 0:
{
int ans;//用来存放答案
cout<<a<<'+'<<b<<'=';
cin>>ans;
if (ans==a+b)
{
numOfRight++;
cout<<"恭喜你答对了!"<<endl;
}
else cout<<"很遗憾答错了,加油!"<<endl;
break;
}
case 1:
{
int ans;
cout<<a<<'-'<<b<<'=';
cin>>ans;
if (a>b)
{
continue;
}
else
{
if (ans==a-b)
{
numOfRight++;
cout<<"恭喜你答对了!"<<endl;
}
else cout<<"很遗憾答错了,加油!"<<endl;
break;
}
}
case 2:
{
int ans;
cout<<a<<'*'<<b<<'=';
cin>>ans;
if (ans==a*b)
{
numOfRight++;
cout<<"恭喜你答对了!"<<endl;
}
else cout<<"很遗憾答错了,加油!"<<endl;
break;
}
case 3:
{
int ans;
cout<<a<<'/'<<b<<'=';
cin>>ans;
if (b==0 && a/b==0)
{
break;
}
else
{
if (ans=a/b)
{
numOfRight++;
cout<<"恭喜你答对了!"<<endl;
}
else cout<<"很遗憾答错了,加油!"<<endl;
break;
}
}
}
numOfQues++;
cout<<"还要再做吗一个题吗?"<<endl;
cin>>inquiry;
}while (inquiry!='n'&&inquiry!='N');
cout<<"你的答题正确率为:"<<numOfRight*100/numOfQues<<"%。再见!"<<endl;
return 0;
}