编写一个智力测试小游戏.由计算机给出10道100以内的四则运算,每道题10分,由用户给出答案,

2022-03-30 教育 101阅读
#include
#include
#include
#include
usingnamespacestd;

voidtest()
{
intall=0,win=0,answer=0;
charchoice;
intn;
inti;

do
{
vectorvs;
vector::iteratorsi;

vectorvc;
vector::iteratorci;

n=rand()%4+2;

for(i=0;i {
vs.push_back(rand()%10+1);
}

for(i=0;i {
switch(rand()%4)
{
case0:
vc.push_back('+'); break;
case1:
vc.push_back('-'); break;
case2:
vc.push_back('*'); break;
case3:
vc.push_back('/'); break;
default:
cout<<"IMPOSSIBLE!\N";
}
}

for(i=0;i {
cout< }
cout<
boolt=true;
inttemp=0;

for(i=0;i {
if(vc.at(i)=='*'||vc.at(i)=='/')
{
if(vc.at(i)=='*')
{
temp=vs.at(i)*vs.at(i+1);
}
else
{
temp=vs.at(i)/vs.at(i+1);
}
//cout<<"test"< vs.at(i)=temp;
si=vs.begin()+i+1;
si=vs.erase(si);

ci=vc.begin()+i;
ci=vc.erase(ci);
i--;
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com