login and register system

May 28, 2018 at 5:03pm
so i wanted to make a login and register system using data structure with vector of objects. now i overcome a problem which is looping and it confuses me on my output and stuff.

Here is the code:

void login(vector<User>& UsersList){
string inpid;
string inppw;
int attempt = 3;
string inpuser;

while(attempt > 0){

cout << "id: ";
cin >> inpid;
cout << "password: ";
cin >> inppw;
for(int i = 0; i<UsersList.size() ; i++){

if(UsersList[i].getID() == inpid && UsersList[i].getPass() == inppw){
inpuser = UsersList[i].getUser();
cout << "Logged in as " << inpuser << endl;
}
break;
}
attempt--;
cout << "Wrong ID and Password. " << endl << "Please try again.(You have " << attempt << " more attempts)" << endl;

if(attempt == 0){
cout << "No more attempts remaining " << endl;
break;
}

}


};

can anyone tell me what i did wrong? seems like my iterate is not quite correct
May 28, 2018 at 6:16pm
The problem is that you don't break out of your while loop, after the login.
The break statement ends only the for loop - also it should be inside the if statement.
May 29, 2018 at 12:27am
The problem is that you don't break out of your while loop, after the login.
The break statement ends only the for loop - also it should be inside the if statement.
can u point out where should i change my codes?
Topic archived. No new replies allowed.