My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Program Listing
password.cpp
// password.cpp
// Prof. Jake R. Pomperada, MAED-IT,MIT
// www.jakerpomperada.com / www.jakerpomperada.blogspot.com
// jakerpomperada@gmail.com
// Bacolod City, Negros Occidental Philippines
#include <iostream>
#include <string>
using namespace std;
int main()
{
string password = "123";
string passwordEntry;
int attempts = 0;
cout <<"\n\n" ;
cout << "\tPassword in C++\n\n";
cout << "\tPlease enter your password: ";
getline(cin, passwordEntry, '\n');
while ( passwordEntry != password && attempts <=2 )
{
cout << "\n";
cout <<"\tPassword Attempt No. : " <<attempts+1;
cout << "\n";
cout << "\tEnter Password Again : ";
getline(cin, passwordEntry, '\n');
attempts++;
}
if ( passwordEntry == password && attempts <=3 )
{
cout << "\n";
cout << "\tAccess Granted in the System.";
}
else
{
cout << "\n";
cout << "\tSorry, you are only allowed 3 password login attempts.";
cout << "\n\n";
}
}
No comments:
Post a Comment