This is for an assignment. I've been at it for hours and hours yet can't seem to get it right.
First ask for the userid. If the user id matches the special “back-door” user id, then no password should be requested or required.
If the userid does not match the backdoor, request a password.
Then using
only a single if - else condition statement check if the user ID and password are correct or if the back-door ID was entered. This will require the use of the || and && logical operators.
If either don’t match, then a “Incorrect userid or password” message is displayed.
The user has up to 3 tries to log in. If they fail, then an “Access denied” message of your choosing is displayed, and the program exits.
__________
Can someone explain to me how to get out of the while loop?
Does the bold mean just an else and an else if?
And how would I go about making the access denied.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string userName, passWord;
const string masterUser = "Mperson";
const string masterPass = "masterP";
const string specialUser = "vipPerson"; //stored as “string constants” so they can’t be changed.
cout << "Hello! Please login. "; // login screen is presented
while (userName != specialUser)
{
cout << "What is your username? "; cin >> userName;
if (userName == masterUser)
{
cout << "Enter password: "; cin >> passWord;
}
else if (passWord != masterPass && userName != specialUser && userName != masterUser)
{
cout << "Error. Invalid username or password." << endl;
}
}
cout << "no password required" << endl;
system("pause");
return 0;
| |