jeudi 30 avril 2015

how to limit the number of inputs for the following code? c++

so basically this code below is nothing but three stores from which user buys guns. user has to press exit to get out of one store and go into other.

I want to put a limit on the user that he can overall buy only 10 guns collectively from all three sections.

For example, if the user buys 10 guns from the first store buying from the other stores process should be skipped then. And suppose if the user buys 6 guns from first store and 4 from the other then the third store should be skipped.

Any ideas how to implement this?

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;
}

Aucun commentaire:

Enregistrer un commentaire