#include <iostream>
#include <ctime>
using namespace std;
void mkelement(int& a,int& b,int& op)
{
op=rand()%2;
a=rand()%50;
if(op) b=rand()%(50-a);
else b=rand()%50;
if(a<b) { int t=a;a=b;b=t; }
}
int main()
{
srand((unsigned)time(0));
cout<<"考试开始,每题10分,每题有三次机会:"<<endl;
int a,b,op,result,answer;
int score=0;
int lvl[3]={10,7,5};
for(int i=0;i<10;i++)
{
cout<<"第"<<(i+1)<<"题:";
mkelement(a,b,op);
if(op)
{
cout<<a<<"+"<<b<<"=";
result=a+b;
}
else
{
cout<<a<<"-"<<b<<"=";
result=a-b;
}
int t=0;
while(1)
{
cin>>answer;
if(cin.fail())
{
cin.clear();
cin.sync();
cout<<"输入错误!重输:";
continue;
}
if(answer==result)
{
cout<<"回答正确+"<<lvl[t]<<"分"<<endl;
score+=lvl[t];
break;
}
else
{
t++;
if(t>=3)
{
cout<<"3次错误,不计分,正确答案是:"<<result<<endl;
break;
}
cout<<"回答错误!!重新回答:";
}
}
}
cout<<"得分:"<<score<<endl;
cout<<"等级:";
switch(score/10)
{
case 10:
case 9: cout<<"SMART"<<endl; break;
case 8: cout<<"GOOD"<<endl; break;
case 7: cout<<"OK"<<endl; break;
case 6:cout<<"PASS"<<endl;break;
default:cout<<"TRY AGAIN"<<endl;
}
return 0;
}
温馨提示:答案为网友推荐,仅供参考