dimanche 7 juillet 2019

Is there a way to stop the loop repeating more than once when running

I want to build a simple questionnaire program. When i run the code it repeats the statement twice when i want it to run only once and not repeat the cout statements. This only happens when i use strings and not characters. Sorry for the clumsy writing.enter image description here

The code is below:

    cout<<"Hello would you like to answer a few questions?"<<endl<<"Please input y or n"<<endl;
    cin>>response;
    {  do{
        if((response_1=="yes")||(response=='y')){
        cout<<"please continue:"<<endl;
        break;}
    else if((response_1=="no")||(response=='n')){
        cout<<"Please exit the program then:"<<endl;
        }
    else{
        cout<<"Wrong input";
    }
}    while((response_1!="yes")||(response!='y'));
}

Aucun commentaire:

Enregistrer un commentaire