Why is my While Loop getting skipped? c++ -


the program skips on while loops , ends. super frustrating. put value of anscheck false right before while loop. no luck. program none of in while loop. here's relevant code:

bool anscheck; anscheck = false; while (anscheck = false) {     getline(cin, ans1);     if (ans1 != "t" || ans1 != "f")     {         cout << "please enter t true or f false" << endl;         cout << "answer not t or not f" << endl; // debugging     }     else     {         anscheck = true;         cout << "changed bool true" << endl;     } } 

you need use comparison operator equality == instead of assignment operator =.

while (anscheck == false) {     // ... } 

also, mentioned in comment below answer, condition in if statement never being evaluated true. compare strings, should use strcmp, returns 0 when contents of both c-strings equal. see this reference more information.

if (strcmp(ans1, "t") != 0 && strcmp(ans1, "f") != 0) {     // ... } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -