c++ – It seems jump to case label in switch statement from case 6 to 9 and I don’t know why

#include<iostream>
#include<string>

using namespace std;

#define SIZE 1000

struct Reservation

{

    string time;
    string day;
    string month;
    string year;
    string hairstylists;
};

struct BeautySalon

{

 string phone;

  string name;

  string address;

  string favhair;

  Reservation reservation;

  string nationality;

  string specality;

}; 

custList[SIZE], hairList[SIZE] ,rev[SIZE];



void readinC(int ctr)
 
{
    cout<<"Enter the name of the Customer: ";

    cin>>custList[ctr].name;

    cout<<"Enter your phone number: ";

    cin>>custList[ctr].phone;

    cout<<"Enter your address: ";

    cin>>custList[ctr].address;

    cout<<"Enter favorite hair stayle: ";

    cin>>custList[ctr].favhair;
    
}

void readinH(int ctr)


{

    cout<<"Enter the name of the Hair stylists: ";

    cin>>hairList[ctr].name;

    cout<<"Enter the phone number: ";

    cin>>hairList[ctr].phone;

    cout<<"Enter the specialty: ";

    cin>>hairList[ctr].specality;

    cout<<"Enter the nationality: ";

    cin>>hairList[ctr].nationality;
    
}

void displayC( int ctr){ 


     for(int i=0;i<ctr;i++){
        
    cout<<"Name: ";
    cout<<custList[i].name<<endl;
    cout<<"phone number: ";
    cout<<custList[i].phone<<endl;
    cout<<"address: ";
    cout<<custList[i].address<<endl;
    cout<<"favorite hair stayle: ";
    cout<<custList[i].favhair;

     }
    
}

void displayH( int ctr){ 

     for(int i=0;i<ctr;i++){
        
    cout<<"Name: ";
    cout<<hairList[i].name<<endl;
    cout<<"phone number: ";
    cout<<hairList[i].phone<<endl;
    cout<<"specialty: ";
    cout<<hairList[i].specality<<endl;
    cout<<"nationality : ";
    cout<<hairList[i].nationality;

     }
    
}

bool searchC(string key,int ctr){
    
        for(int i = 0; i < ctr; ctr++)
    {
        if(key == custList[i].name)
        {
            return true;
        }
    }
    return false;
}



bool searchH(string key,int ctr){
    
        for(int i = 0; i < ctr; ctr++)
    {
        if(key == hairList[i].name)
        {
            return true;
        }
    }
    return false;
}


string updateC(int ctr)


{

    string input;

    cout<<"enter any name: ";

    cin>>input;
    
    for(int i = 0; i <= ctr; ctr++)
    { 
        if(input == custList[i].name)
        {string replace;
        cout<<"enter your new name: ";
        cin>>replace;
        custList[i].name=replace;
        return custList[i].name ;
    
        }
    }
}



string updateH(int ctr)

{

    string input;

    cout<<"enter any name: ";

    cin>>input;

    
    for(int i = 0; i <= ctr; ctr++)
    { 
        if(input == hairList[i].name)
        {string replace;
        cout<<"enter your new name: ";
        cin>>replace;
        hairList[i].name=replace;
        return hairList[i].name ;
    
        }
    }
}

string delet(int ctr)

{

    string input;

    cout<<"enter any name: ";

    cin>>input;

    
    for(int i = 0; i < ctr; ctr++)
    { 
        if(input == custList[i].name)
        {input.clear();
        custList[i].name=input;
        return custList[i].name ;
    
    
        }
   }
}

void readinRv(int ctr)

{


    cout<<"Enter the date DD MM YYYY sprated by space: ";

    cin>>rev[ctr].reservation.day>>rev[ctr].reservation.month>>rev[ctr].reservation.year;

    cout<<"Enter your reservation time: ";

    cin>>rev[ctr].reservation.time;

    cout<<"Enter the name for hair stylists";

    cin>>rev[ctr].reservation.hairstylists;
    
}

string cancel(int ctr)

{

string day,month,year;

    cout<<"enter any Date DD MM YYYY sperated by space: ";

    cin>>day>>month>>year;

    
    for(int i = 0; i < ctr; ctr++)

    { 

        if((day == rev[i].reservation.day)&&(month == rev[i].reservation.month)&&(year == rev[i].reservation.year))

        {day.clear();

        rev[i].reservation.day=day;

        rev[i].reservation.month=day;

        rev[i].reservation.year=day;

        rev[i].reservation.time=day;

        rev[i].reservation.hairstylists=day;
        
        return 

rev[i].reservation.day+rev[i].reservation.month+rev[i].reservation.year+rev[i].reservation.time+rev[i].reservation.hairstylists;

    
    
        }
  

 }


}

    bool searchHS(string key,int ctr)

{
    

        for(int i = 0; i < ctr; ctr++)

    {
        if(key == rev[ctr].reservation.hairstylists)

        {
            return true;

        }

    }

    return false ;

}


int main()

{
    int choice;

    int counterC = 0, counterH= 0;

    
    do

    {
        cout << "1. Add New customer or hairstylistsn";

        cout << "2. Display All customers recordsn";

        cout<<  "3. Update the customer or hairstylistsn";

        cout<<  "4. Delete the Datan";

        cout<<  "5. Search for specific customer detailsn";

        cout<<  "6. Search for available haristylists n";

        cout<<  "7. Add new reservation n";

        cout<<  "8. Cancel reservation n";

        cout << "9. Quitn";
        
        
        cout << "nnEnter your choice: ";

        cin >> choice;
        
        switch(choice)

        {
            case 1:

                int add;

                cout<<"npress 1 to add new customer, 2 to add new haristylists:  ";

                cin>>add;

                if(add==1)

                {readinC(counterC);

                counterC++;

                }
                
                if (add==2)

                {readinH(counterH);

                counterH++;

                }
                
            break;

            
            case 2:
                
                int display;

                cout<<"npress 1 to display all the customeres information, 2 to diplay all haristylists information:  ";

                cin>>display;

                if(display==1)

                displayC(counterC);

                
                if (display==2)

                displayH(counterH); 

            break;

            
            case 3:
                int update;

                cout<<"npress 1 to update the customere information, 2 to update haristylists 
information:  ";

                cin>>update;

                if(update==1)

                cout<<"the new name is: "<<updateC(counterC);
                
                if(update==2)

                updateH(counterH);

                cout<<"the name updated scssfulu";

            break;
            
            case 4:
                cout<<"scsess: "<<delet(counterC);

                counterC--;

            break;
            
            case 5:
               int search;

               string key;

                cout<<"npress 1 to search the customere information, 2 to saerch haristylists information:  ";

                cin>>search;
                
                if(search==1)

                {

                cout<<"nEnter any name to search for: ";

                cin>>key;

                searchC(key,counterC);

                if(searchC(key,counterC)==true)

                cout<<"nthe key is found";

                else

                cout<<"nthe key isn't found";

                }

                
                if(search==2)

                {

                cout<<"nEnter any name to search for: ";

                cin>>key;

                searchH(key,counterH);

                if(searchH(key,counterH)==true)

                cout<<"nthe key is found";

                else

                cout<<"nthe key isn't found";

                }
                
            break;
            
            case 6:

            string nameH;

            bool available;

            cin>>nameH;

            
            available=searchHS(nameH,counterC);

            if(available==true)
        
            cout<<"The hair stylists not available";

            else

            cout<<"The hair stylists available";

            
            break;
             
            case 7:

            readinRv(counterC);


            break;

            
            case 8:

            cancel(counterC);

            break;

            
            case 9:

            cout<<" Quite";

            break;

                
            default:

         cout << "Input error, try again!nn"; 
                    
        }   
            
    }while(choice !=10);

    return 0;
        
}

Leave a Comment