Modify the solution to Brute-Force Attack to include a maximum of 5 passcode attempts. Each time the user enters an incorrect passcode, they should be prompted of how many passcode attempts remain. If there are 5 failed passcode attempts the while loop should break and inform the user that the authorities have been alerted!
#include <iostream>
using namespace std;
int main()
{
int count=5;
string passcode="123@Abc.";
while(true){
string userpasscode;
cout<<"\nEnter password: ";
cin>>userpasscode;
if (passcode==userpasscode){
cout<<"\nCorrect password.";
break;
}
else{
count--;
if (count==0){
cout<<"\nIncorrect password. The authorities have been alerted! ";
break;
}
else{
cout<<"\nIncorrect password. You have "<<count<<" attempts remaining!";
}
}
}
return 0;
}
Comments
Leave a comment