How to restart a loop automatically

If you view my code below My question pertains to function called valuemeal1()

within the code I have multiple loops each checking if the proper values have been entered

my question is if for example someone is asked if they want fries   and the answer is neither yes or no
they type  'yet' or make a typo  how can I have the program loop back..currently I have it say that is not a valid answer but I also want it to then re ask if they want fries or not..

I also have another qustion not sure if I should post a new one but i'll ask anyway..

How can I have my answer not case sensitive...I want the user to be able to enter   Yes or yes for an answer

//Jeffrey Calandra
//2/11/08


#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>

using namespace std;


void menu(void)
{
     cout <<"Enter Menu Item " << endl;
     cout <<"1 = Double Quarter Pounder w/Cheese Value Meal" <<endl;
     cout <<"2 = Hoagie" <<endl;
     cout <<"3 = Soda" <<endl;
     cout <<"4 = Fries" <<endl;
     cout <<"5 = Chips" <<endl;
     cout <<endl;
     cout <<"0 = quit" <<endl;
     cout <<endl;
}

void valuemeal1(void)
{
     float qty;
     string y = "yes";
     string n = "no";
     string s = "Small";
     string m = "Medium";
     string l = "Large";
     string fries;
     string supersize;
     string soda;
     cout <<"Enter the quanity" <<endl;
     cout <<endl;
     cin  >>qty;
     cout <<endl;
     cout <<"Would you like fries with that? (yes or no): ";
     cin  >>fries;
     if(fries == y)
     {
              cout <<endl;
              cout <<"Super Size the Fries ? (yes or no): ";
              cin  >>supersize;
              if(supersize == y)
              {
                           cout <<endl;
                           cout <<"What Size Soda ? (Small,Medium,Large): ";                          
                           cin  >>soda;
                           if((soda == s) || (soda == m) || (soda == l))
                           {
                                    cout <<endl;
                                    cout <<"You have ordered" <<endl;
                                    cout <<qty <<" Double Quarter Pounder(s) w/Cheese" <<endl;
                                    cout <<"Super Size Fries" <<endl;
                                    cout <<soda <<" soda" <<endl;
                                    cout <<endl;
                                    cout <<"Thank you for your purchase" <<endl;
                                    cout <<endl;
                           }
                           else
                           {
                               cout <<endl;
                               cout <<"That is not a valid soda size" <<endl;
                               cout <<endl;
                           }
              }
              else
              {
                  if(supersize != n)
                  {
                               cout <<endl;
                               cout <<"That is not a valid Supersize Option" <<endl;
                               cout <<endl;
                  }
                  if(supersize == n)
                  {
                  cout <<endl;
                  cout <<"What Size Soda ? (Small,Medium,Large): ";                          
                  cin  >>soda;
                  if((soda == s) || (soda == m) || (soda == l))
                  {
                           cout <<endl;
                           cout <<"You have ordered" <<endl;
                           cout <<"Double Quarter Pounder w/Cheese" <<endl;
                           cout <<"Regular Fries" <<endl;
                           cout <<soda <<" soda" <<endl;
                           cout <<endl;
                           cout <<"Thank you for your purchase" <<endl;
                           cout <<endl;
                           }
                           else
                           {
                               cout <<endl;
                               cout <<"That is not a valid soda size" <<endl;
                               cout <<endl;
                           }
                  }
                  }
     }
     else
     {
         if(fries != n)
         {
                  cout <<endl;
                  cout <<"That is not a valid fries option" <<endl;
                  cout <<endl;
                 
         }
         if(fries == n)
         {
         cout <<endl;
         cout <<"What Size Soda ? (Small,Medium,Large) : ";
         cin  >>soda;
         if((soda == s) || (soda == m) || (soda == l))
         {
                  cout <<endl;
                  cout <<"You have ordered" <<endl;
                  cout <<"Double Quarter Pounder w/Cheese" <<endl;
                  cout <<"No Fries" <<endl;
                  cout <<soda <<" soda" <<endl;
                  cout <<endl;
                  cout <<"Thank you for your purchase" <<endl;
                  cout <<endl;
         }
         else
         {
             cout <<endl;
             cout <<"That is not a vaild soda size" <<endl;
             cout <<endl;
         }
         }
     }                                  
                           
     cout <<endl;
     system("pause");
}

void hoagie(void)
{
     char b;
     cout <<"Enter Size of Hoagie " <<endl;
     cout <<"(L) for Large or (S) for small ";
     cin  >>b;
     if((b == 'L') || (b == 'S'))
     {
           cout <<endl;
           cout <<"The size of hoagie you ordered = : " <<b <<endl;
           cout <<endl;
         
     }
     else
     {    
     
           cout <<endl;
           cout <<"YOU DID NOT ENTER A VALID SIZE";
           cout <<endl;
     }
}

void soda(void)
{
     char c;
     cout <<"Enter the Size of Soda " <<endl;
     cout <<"(L) for Large" <<endl;
     cout <<"(M) for Medium" <<endl;
     cout <<"(S) for Small" <<endl;
     cout <<endl;
     cin  >>c;
     if((c == 'L') || (c == 'M') || (c == 'S'))
     {
           cout <<endl;
           cout <<"The size of soda you ordered = : " <<c <<endl;
           cout <<endl;
     }
     else
     {
         cout <<"YOU DID NOT ENTER A VALID SIZE";
         cout <<endl;
     }
}

void fries(void)
{
     float d;
     cout <<"Enter the amount of Fries " <<endl;
     cin  >>d;
     cout <<endl;
     cout <<"You purchase " <<d <<" fries " <<endl;
     cout <<endl;
}

void chips(void)
{
     string e = "Sour Cream";
     string f = "Ranch";
     string g = "Regular";
     string type;
     
     cout <<"Enter the type of Chips " <<endl;
     cout <<"Sour Cream " <<endl;
     cout <<"Ranch " <<endl;
     cout <<"Regular " <<endl;
     cout <<endl;
     cin  >>type;
     if((type == e) || (type == f) || (type ==g))
     {
             
           cout <<endl;
           cout <<"Your purchased " <<type <<" chips " <<endl;
           cout <<endl;
     }
           
 
     else
     {
         cout <<endl;
         cout <<"YOU DID NOT ENTER A VALID TYPE" <<endl;
         cout <<endl;
     }
}


int main()
{
   
    int a;  
    do
    {
        cout <<endl;
        menu();
        cin >> a;
        cout <<endl;
                         
                     switch(a)
                     {
                                      case 1: valuemeal1();
                                      break;
                                      case 2: hoagie();
                                      break;
                                      case 3: soda();
                                      break;
                                      case 4: fries();
                                      break;
                                      case 5: chips();
                                      break;
                     
                                     
                     }
    }while (a!= 0);  
       
return 0;
}


Thanks
WestonGroupAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You could just make that
fries = "";
 
while (fries != y && fries != n)
{
     cout <<"Would you like fries with that? (yes or no): ";
     cin  >>fries;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
itsmeandnobodyelseCommented:
You best put all user iput into a separate function like you did for 'soda'. Then loop in the function until you have valid input (or quit)

bool soda(char& c )
{
     c = ' ';
     while (true)
     {
        cout <<"Enter the Size of Soda " <<endl;
        cout <<"(L) for Large" <<endl;
        cout <<"(M) for Medium" <<endl;
        cout <<"(S) for Small" <<endl;
        cout <<endl;
        cin  >>c;
        if((c == 'L') || (c == 'M') || (c == 'S'))
        {
            cout <<endl;
            cout <<"The size of soda you ordered = : " <<c <<endl;
            cout <<endl;
            return true;
        }
        else if (c == 'Q' || c == 'q')
            return false;
        else
        {
           cout <<"YOU DID NOT ENTER A VALID SIZE";
           cout <<endl;
        }
     }
}

The loop would continue until valid input is given.

Note, in case of 'quit' the function would return false.

Regards, Alex

0
Infinity08Commented:
>> How can I have my answer not case sensitive...I want the user to be able to enter   Yes or yes for an answer

You can by default transform all input to uppercase (or lowercase), and then check.
0
itsmeandnobodyelseCommented:
>>>> You can by default transform all input to uppercase (or lowercase), and then check.

e. g.

    cin >> c;
    c = toupper(c);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.