简体   繁体   中英

I am having error the dowhile loop is not working

the task for checking the priority string is not working i have included string header file of cstring but still. i want to check whether the input inserted by user is in the case which i have provided or else it should ask again to enter the priority. but when i am running it is not doing in the same way i want it to be.

 void add_task(){
                bool check=true;
                system("color 4F");
                cout<<"Enter the task: ";
                getline(cin,task);
                do{
                cout<<endl<<"Priority(High/Medium/Low) : ";
                gets(priority);
                **code to check whether the priority order is correct??**
                if (strcmpi(priority,"High") == true) {
                    check=true;
                    break;
    //comparing text 
                }
                else if(strcmpi(priority,"Medium") == true ){
                    check=true;
                    break;
                }
                else if(strcmpi(priority,"Low") == true){
                    check=true;
                    break;
                }
                else {
                    check=false;
                    cout<<endl<<"Please enter Correctly";
                }
            }
            while (check==false);
                cout<<endl<<"Due in days: ";
                cin>>due;
            }

you write

while (check == false);

it means when check is false process stuck there for life unless another thread or process change it you can use this code

void add_task()
{
    bool check = false;
    system("color 4F");
    cout<<"Enter the task: ";
    getline(cin,task);
    while (check == false) {
    cout<<endl<<"Priority(High/Medium/Low) : ";
    gets(priority);
    if (strcmpi(priority,"High") == true) {
        check = true;
        break;
     
    } else if (strcmpi(priority,"Medium") == true ) {
          check = true;
          break;
    } else if (strcmpi(priority,"Low") == true) {
          check = true;
          break;
    } else {
          check = false;
          cout<<endl<<"Please enter Correctly";
    }
        cout<<endl<<"Due in days: ";
        cin>>due;
    }
}

so when check is false while repeat and when check is true while will be finished

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM