Hello everybody!
I am creating a Book library system in C++.
I created a login class where the user types in a username and password and if successful is able to log into the menu system.
Now, everything goes well unless and untill the user types in the right credentials but things fall apart when the user is given three chances if the username and password is not right. After three chances the console closes down.
But in my case after three failed attempts the user is able to access the menu system anyhow regardless of the user credentials???
please check my code and advise me accordingly
#include <include.h>
#include <exit.h>
void login()
{
string username; //This is a string variable calld username(string variables r 4 saving text)
string password; //this is a string variable calld password
int tries = 3; //This is a integer variable tries.Here we save the number of tries to ques the
int success =0; // false
//username and password(integer = 4 saving numbers not decimal numbers).And we set it on 0
while(tries && !success)
{
cout << "Username: "; //displays Username: on the screen
cin >> username; //Saves the input in the variable username
cout << "Password: ";
cin >> password;
if(username == "admin" && password == "getaccess") //if username is the same as Admin and password is the
//same as GetAcces then:
{
system("cls"); //clear screen
cout << "You have got access. \n";
success =1;
}
else //else:
{
tries--; //tries + 1
}
}
}
This class gives access to the main menu
#include "include.h"
#include "menu.h"
#include "exit.h"
#include "login.h"
int main()
{
login();
printMenu();
}