Why won't this C++ While loop work? -


i'm trying user put in name/age , verify if it's correct. if not 4 tries before program abort. while loops don't loop, instead continue on next loop. i've tried variation of things inside while parenthesis (op != 1) (!(op = 1)) etc.

int main() {     system("color 0a");     string name;     int age;     int tries = 0;     int op = 0;     cout << "hello user" << endl;     sleep(3000);     while ((op != 1) && (tries < 4)) {         name = entname(name);         cout << "so name " << name << "?" << endl;         cout << "enter '1' yes or '2' no. ";         cin >> op;         if (op == 1) {             cout << "perfect!";         }                    if (op == 2) {             cout << "please try again!";             tries+ 1;             }         if (tries = 4) {             //abort program         }        }     int op2 = 0;     int tries2 = 0;     while ((op2 != 1) && (tries2 < 4)) {         op2 = 3;         age = entage();         cout << "so " << age << " years old?" << endl;         while ((op2 != 1) && (op2 != 2)) {             cout << "enter '1' yes or '2' no. ";             cin >> op2;             if (op2 == 1) {                 cout << "perfect!\n";             }             if (op2 == 2) {                 cout << "please try again!\n";                 tries2++;             }             if (tries2 = 4) {                 //abort programhi             }         }     }     return 0; } 

i'm new c++ i'm sorry if have simple answer. anyway, i've been debugging on half hour , looked online 20+ minutes.

if (tries = 4) {             //abort program         }    

change

if (tries == 4) {             //abort program         }    

and

f (op == 2) {             cout << "please try again!";             tries+= 1; // tries+ 1;             } 

you can increment value in c++ tries+ 1;. either use tries+= 1; or tries++;


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -