[C++] Password Protected Program Using While Loop
This short source code will show you how to make a password protected program using a while loop. If you have any questions or comments, post them here.
Source Code:
Code:
#include <iostream.h>
#include <string.h>
using namespace std;
int main()
{
string pass; //this is what ever you set your password to
cout<<"This program is password protected. Enter the password: ";
cin>>pass;
while(pass!="qwerty123") //sets a loop, so while they don't put the password in as qwerty123 (or whatever you set yours to)
{ //then the program wont start, it will just give an error message.
cout<<"That is not the password, the program will not start until you get the password right."<<endl;
cout<<"Try again: ";
cin>>pass;
}
cout<<"Access Granted, program will now start."<<endl;
// the rest of your program would go BELOW this while loop. Make sure it's after the while loop.
// the while loop is basically outputting the message until the condition is broken.
// if you had your program before the loop, it would still go through and not see the while loop until after the program.
//That's how you make a password protected program using a while loop.
system ("PAUSE");
return 0;
}