Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string password = "emiliani";
string passwordEntry;
int attempts = 1;
cout << "Please enter your password: ";
getline(cin, passwordEntry, '\n');
while ( passwordEntry != password && attempts <=4 )
{
cout << "Please try again: ";
getline(cin, passwordEntry, '\n');
attempts++;
}
if ( passwordEntry == password && attempts <=5 )
{
cout << "Access granted";
}
else
{
cout << "Maximum attempts reached! The program will terminate!";
}
}