【发布时间】:2015-07-11 00:11:56
【问题描述】:
所以基本上下面的这段代码只不过是用户购买枪支的三个商店。用户必须按退出才能离开一家商店并进入另一家商店。
我想限制用户总共只能从所有三个部分购买 10 支枪。
例如,如果用户从第一家商店购买了 10 支枪,则应跳过从其他商店购买的过程。假设用户从第一家商店购买了 6 支枪,从另一家商店购买了 4 支枪,那么应该跳过第三家商店。
有什么想法可以实现吗?
cout<<endl<<"enter the guns you want from store 1 and press exit to buy from other sstore"<<endl;
cin>>a;
while(a!="exit")
{
tmp = false;
for(map<string,int> :: const_iterator it = storeone.begin(); it != storeone.end(); ++it)
{
if(it->first == a)
{
b=it->second;
setfinalguns(a,b);
cout<<"you bought "<<a<<" for price "<<b<<endl;
spentmoney(b);
tmp = true;
break;
}
}
if(!tmp)
cout<<"This gun is not available"<<endl;
cin>>a;
}
cout<<"enter the items you want to from store two and press exit to buy from other store"<<endl;
cin>>c;
while(c!="exit")
{
tmp = false;
for(map<string,int> :: const_iterator it = stroretwo.begin(); it != storetwo.end(); ++it)
{
if(it->first == c)
{
d=it->second;
setfinalguns(c,d);
cout<<"you bought "<<c<<" for price "<<d<<endl;
spentmoney(d);
tmp = true;
break;
}
}
if(!tmp)
cout<<"Thisgun is not available"<<endl;
cin>>c;
}
cout<<"enter the guns you want from store three and press exit to buy from other store"<<endl;
cin>>e;
while(e!="exit")
{
tmp = false;
for(map<string,int> :: const_iterator it = storethree.begin(); it != storethree.end(); ++it)
{
if(it->first == e)
{
f=it->second;
setfinalguns(e,f);
cout<<"you bought "<<e<<" for price "<<f<<endl;
spentmoney(f);
tmp = true;
break;
}
}
if (!tmp)
cout<<"This gun is not available"<<endl;
cin>>e;
break;
}
【问题讨论】:
-
像
if( number_of_guns == 10 ) break;这样的东西怎么样
标签: c++ c++11 conditional-statements