If the user enters a wrong password I want the "wrong password" message to flash on the screen for like 3 seconds and then direct the user to the access() function..so that he can try again.
Is there any way to do that?
This is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void access()
{
cout << "W E L C O M E T O T H E L I B R A R Y D A T A B A S E" << endl;
cout << "-------------------------------------------------------------------------------" << endl;
cout << "Enter your password: " << endl;
string adminpass;
if (adminpass == "admin")
{
adminmain();
}
else
{
cout << "Wrong Password! " << endl;
// Go to a screen with wrong password message and then display the function again.
}
void access()
{
bool ok = false;
string adminpass;
int ck = 0;
cout << "W E L C O M E T O T H E L I B R A R Y D A T A B A S E" << endl;
cout << "-------------------------------------------------------------------------------" << endl;
while( !ok )
{
cout << "Enter your password: " << endl;
cin >> adminpass;
if (adminpass == "admin")
{
ok = true;
cout << "Password accepted!!" << endl;
Sleep(2000); // Needs #include <Windows.h>
adminmain();
}
else
{
cout << "Wrong Password! " << endl;
ck++; // Give user only 3 tries to enter correct password
// Go to a screen with wrong password message and then display the function again.
Sleep(3000);// waits for 3 seconds
}
if(ck==3)
{
cout << "You failed to enter correct password!" << endl;
cout << "Program will now terminate!" << endl;
Sleep(3000);
return;
}
}
}
}
Yes! its executing perfectly.
The sleep(2000) kept the message for about 2000 seconds.
So I used sleep(2) instead.
Where do i learn all this( like sleep() function etc)?
This is so cool. I generally refer to c++ primer plus for any problems and bugs.
Any books u recommend for learning these things.
btw i use a mac so pl don't suggest windows related books.
Thank You so much!