vendredi 6 octobre 2023

case 2 has to print out no data if case 1 has not been pick before: do/while switch C++

do{ (Prompt user for an option)

    switch(option)
    {
        case 1: (prompt user for name and birthYear)
            
        case 2:
            
            if (option == 2|| option !=3) {
                cout <<"\nNo data ";
            }else {
            cout <<"\nUser's name ("<< userName<<birthYear<<birthYear<<endl;
            
            }
            
            break;
            
        case 3:cout<<"Exiting program"<<endl;
            break;
         
    }}
    while (option!=3);

return 0; }

It an infinite loop and if option 1 is chosen before op2 I have to print out the given info but if not then I have to print out "no data". I'm not sure what I'm doing wrong. I think im supposed to be putting loop in cases. I've tried other methods and nothing. should I keep up with the options outside of the case, right under the do and then used that in case 2. im running out of options.

Aucun commentaire:

Enregistrer un commentaire