Answer to Question #269499 in C++ for ujoo

Question #269499

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! 


1
Expert's answer
2021-11-21T04:55:19-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS