I'm new to programming and so I bought a book to help me learn C++, in the book it asks me to do a practice assignment where I must create a program that allows me to take input of multiple usernames and passwords, match them, and also allow someone who incorrectly enters information to try entering it again. I've wrote the following program in order to do so. If anyone can also shed any light on how to make the program allow for retry of username/password entry without ending the program that would also be greatly appreciated. Thank you!
#include <iostream>
#include <string>
using namespace std;
int main()
{
string username1="Varun";
string username2="Agne";
string username3="Geetha";
string username4="Mohan"; //Usernames for accounts
string pass1="PassworD";
string pass2="PASSWORD"; //Passwords for accounts
string pass3="password";
string pass4="Password";
string Uattempt; //User input for username
string Pattempt; //User input for password
cout << "Please enter your username.\n";
cin >> Uattempt;
cout << "Please enter your password \n"; //Asks for username and password entry by user
cin >> Pattempt;
if(Uattempt!=username1 || username2 || username3 || username4)
{
cout << "Access Denied. Incorrect username or password. Please retry.\n"; //If username does not match possible entries, program will ask to retry
}
if(Pattempt !=(pass1||pass2)&&(pass3||pass4)
{
cout << "Access Denied. Incorrect username or password. Please retry.\n"; //If password does not match possible entries, program will ask to retry
}
if (Uattempt&&Pattempt==username1&&pass1||username2&&pass2||username3&&pass3||username4&&pass4)
{
cout << "Access Granted. Welcome " + <<Uattempt<< + ".\n";
}
else
{
return 0;
}
}