Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Abhishek Prasad
- // COSC 1410
- // Haberdar Tu-Th 8:30-10:00
- // March 13, 2016
- #include <iostream>
- using namespace std;
- int main()
- {
- int unInput; // declaring variables for Input for Password and Username
- int pwInput;
- int UN = 123456; // Username
- int PW = 1234; // temporary password
- for (int tries = 1; tries < 4; tries ++)
- {
- cout << "Enter Username: ";
- cin >> unInput;
- cout << "Enter Password ";
- cin >> pwInput;
- if (unInput == UN && pwInput == PW) // if statement - checks if pw and un are correct. if true, the
- {
- cout << "Congratulations! Now please enter your new password" << endl;
- bool match = false;
- do
- {
- cout << "The new password must be a 4 digit number and different from the temporary password. Enter new password:" << endl;
- cin >> pwInput;
- if (pwInput > 999 && pwInput < 10000 && pwInput != PW)
- {
- PW = pwInput;
- cout << "You have changed your PW successfully! Please re-login."<<endl;
- match = true;
- }
- } while (match != true);
- break; // breaks program
- }
- else // if the program failed 3 times
- {
- cout << "Invalid credentials, program terminates after 3 falied attemps, number of failed tries= " << tries << endl;
- }
- if (tries == 3) // if tries are 3 it will run the following statement
- {
- cout << "The system cannot be accessed. The program has ended.";
- }
- }
- for (int tries = 1; tries < 4; tries ++) // these statements run after the statement
- {
- cout << "Enter Username: ";
- cin >> unInput;
- cout<< "Enter Username: ";
- cin >> pwInput;
- if (unInput == UN && pwInput == PW)
- {
- cout << "Access granted! Enjoy :)";
- break;
- }
- else
- {
- cout << "Wrong password. Number of tries left: " << tries << endl;
- }
- if (tries == 3)
- {
- cout << "The system cannot be accessed. The program has ended."<<endl;
- }
- }
- return 0;
- }
- // end of program :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement