// Example program
#include <iostream>
#include <string>
#define ACCOUNT_MAX 3
using namespace std;
class User
{
private:
struct Accounts {string user, password, firstName;};
struct Accounts accs[ACCOUNT_MAX];
bool online;
void setAccounts()
{
accs[0].user = "admin";
accs[0].password = "adminpw";
accs[0].firstName = "Administrator";
accs[1].user = "user01";
accs[1].password = "user01pw";
accs[1].firstName = "User 01";
accs[2].user = "user02";
accs[2].password = "user02pw";
accs[2].firstName = "User 02";
}
public:
int Access(string user, string password)
{
int count = 0;
for (; count <= ACCOUNT_MAX; count++)
{
if (user.compare(this->accs[count].user) == 0 && password.compare(this->accs[count].password) == 0)
{
this->online = true;
break;
}
else
this->online = false;
}
return this->online;
}
User() {}
~User() {}
};
int main()
{
class User *managment = new User();
string localUser, localPassword;
cout << "A system [Version 2.0]\n" << endl;
do {
cout << "User: ";
cin >> localUser;
cout << "Password: ";
cin >> localPassword;
} while (managment->Access(localUser, localPassword) == false);
return 0;
}
Could someone tell me why the condition is not read? The program always returns 0.