while loop - im creating a c++ program where the user has 2 attempts in trying a password username combo. If they cant get it they program stops -


this error getting. moving on python c++ , huge adjustment. description of program: write program creates 3 or more valid username/password combinations, prompts user enter username , password. if combination valid, print confirmatory message. if combination invalid on first try, print warning message , let user try 1 more time (prompt them again username , password). if second try correct, print confirmatory message. if second try incorrect, print chiding message. in either case, halt program after second attempt. show output 3 cases: correct username/password on first attempt; correct on second attempt; incorrect on both attempts.

$ g++ username_password.cpp -o username_password username_password.cpp: in function ‘int main()’: username_password.cpp:34:2: error: ‘else’ without previous ‘if’   else if (username != "veasy62" && username != "tveasy62" && username != "terriyon62" && password != "a65908" && password != "a1065908" && password != "aa1065908");   ^     #include <iostream> #include <string>  using namespace std;  int main()  {      int pswrd_attempts = 0;     string username;     string password;     cout << "enter username: " << "\n";     getline( cin, username, '\n' );     cout << "enter password: " << "\n";     getline( cin, password, '\n' );     while (username != "veasy62" && username != "tveasy62" && username != "terriyon62" && password != "a65908" && password != "a1065908" && password != "aa1065908");     {         pswrd_attempts++;         cout << "enter username: " << "\n";         getline( cin, username, '\n' );         cout << "enter password: " << "\n";         getline( cin, password, '\n' );          if (pswrd_attempts > 2)          {             cout << "you've ran out of attempts" << "\n";         }      }     else if (username == "veasy62" && username == "tveasy62" && username == "terriyon62" && password == "a65908" && password == "a1065908" && password == "aa1065908");     {         cout << "correct password!" << "\n";        }      } 

you have semicolon @ end of line define while statement. create kinds of havoc.

the other problem, 1 report, because else clause outside of supposed while scope, rather being attached if.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -