mercredi 22 avril 2015

How to Set Conditions on Input. c++

so basically when an input is entered it has to be checked against two conditions. if its "exit" terminate the while loop immediately and if the a copy of the input exists in the input1(which is a map) only then save it in the finalist(map).

If such input is entered which doesn't exists in input1. the user should be asked again to enter something else. this what i have so far. for exit and for other inputs its working fine.

when i enter a valid input it still says "this item is not in the section..." can someone please help.

what condition should i put to make this work?

cout<<"enter the items you want to buy press exit to buy from other section"<<endl;
cin>>a;
int choice;       

 LOOP: while(a!="exit")
  {
     for(it = input1.begin(); it != input1.end(); ++it)
      {
        if(it->first != a) continue;
        {
        choice=input1[a];
        finallist[a]=choice;
        cout<<"you bought "<<a<<" for price "<<finallist[a]<<endl;
        spentmoney(choice);
        cin>>a;
        if(a== "exit")
         {
         goto LOOP;
         } 
        choice=input1[a];
        finallist[a]=choice;
        cout<<"you bought "<<a<<" for price "<<finallist[a]<<endl;
        spentmoney(choice);           
       }
     }
    cout<<"This Item is not available"<<endl;
    cout<<"Buy something else"<<endl;
    cin>>a;

Aucun commentaire:

Enregistrer un commentaire