Advertisement
ivanwidyan

Password Prompt That Gives 3 Try Attempts

Oct 17th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int PasswordAttempts = 3;
  7.     string Password;
  8.     while (PasswordAttempts >= 0) {
  9.         cout << "Enter your password: ";
  10.         cin >> Password;
  11.         if (Password == "test") {
  12.             cout << "You granted an access!" << endl;
  13.             return 0;
  14.         }
  15.         else
  16.         {
  17.             cout << "Wrong, password! you have " << PasswordAttempts << " try attempts" << endl;
  18.             PasswordAttempts--;
  19.         }
  20.     }
  21.     cout << "You've tried too many attempts, you're blocked" << endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement