My code is a Shop that I am trying to build, it works(Register system working) until I input my User and Password(Login System), after inputting my Username, the program asks me to re-login and it keeps doing it(Pretty sure it is because it is a while true loop). (This is a project, so there are separate different files with constructors and classes.)
Here is part of my Code:
while(true)
{
cout << "Would you like to register or login?" << endl;
string answer = "";
cin >> answer;
if(answer == "register" || answer == "Register")
{
cout << "What would be your designated username?: " << endl;
string newUser;
cin >> newUser;
for(int i = 0; i < 20; i++)
{
if(customers[i] -> username != newUser)
{
cout << "what would be your designated password?: " << endl;
string newPass;
cin >> newPass;
customers[lastRegisteredID] = new Customer(newUser, newPass);
lastRegisteredID++;
break;
}
}
//^Register Part.
}
if(answer == "login" || answer == "Login")
{
cout << "Your username: " << endl;
string UserAttempt;
cin >> UserAttempt;
for(int j = 0; j < 20; j++)
{
if(customers[j] -> username == UserAttempt)
{
cout << "Username Found!" << endl;
tempCustomer = customers[j];
cout << "Your password: " << endl;
string PassAtempt;
cin >> PassAtempt;
if(tempCustomer -> password == PassAtempt)
{
cout << "Password correct \n Successfully logged in." << endl;
loggedin = true;
break;
}
}
}
}
//^Login part.
}