While Loops

I want to make a password and let the person have 3 trys, but i can't seem to get it to work. after the 3rd guess it moves on to my code after the password part. can someone please help me.
heres my sorce code.

thanks,
MM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int main() 
{
	int p = 3;
	while(p > 0)
	{
		string password ="";
		char ch;
		
		cout << "Type The Password To Eenter Program: ";
		ch = _getch();
		while(ch != 13)
		{
			password.push_back(ch);
			cout << '*';
			ch = _getch();
		}
		if (password == "Password1")
		{
		}
		if (p == 0)
		{
			cout << "\nWrong Password\n You Fail!!" << endl;
			_getch();
			return 0;
		}
		else
		{
			system("cls");
			cout << "Wrong Password\n Try Again" << endl;
			p -= 1;
		}
	}
Last edited on
That looks unnecessarily complicated.
1
2
3
4
5
6
7
8
9
10
11
12
int t=0;
bool wrongpassword=1;
while (1){
	//input password
	//set wrongpassword
	if (wrongpassword)
		t++;
	else
		break;
	if (t==3)
		return;
}
Last edited on
Well i wanted to make it so the password didn't show up only *'s

MM
Topic archived. No new replies allowed.