Problem: i run the program enter a wrong password, message box is displayed "wrong password only two tries left." then when i press ok to the first message box the second one comes up automatically, then i press ok again and the third message box comes up automatically.
without ever letting the user press ok to the first message box then they can go back to entering a password press enter on the form then the next message box should come up if password wrong and so fourth.
I have tried not using the while statement, then i thought i would put
break;into each condition but that goes out of the loop and stops incrementing it. then I thought if I changed the messagebox buttons on the form to retry and cancel or even ok and cancel it would of maybe worked. I feel it is probably a simple error thats why ive tryed hard doing different things. but now ive decided to ask for help.
This is my code:
string pas = "password";
txtpas.Focus();
int i = 0;
while (this.txtpas.Text != pas && i<3)
{
if (i == 0)
{
MessageBox.Show("You have entered the wrong password" +
" you only have two tries left!", "two tries ", MessageBoxButtons.RetryCancel);
}
else if (i == 1)
{
MessageBox.Show("You have entered the wrong password" +
" you only have one try left!", "one try ", MessageBoxButtons.RetryCancel);
}
else if (i == 2)
{
MessageBox.Show("You have entered the wrong password" + " you have no tries left!" +
" This application will close", "Wrong password ", MessageBoxButtons.RetryCancel);
Application.Exit();
}
i++;
}
Many thanks!!

New Topic/Question
Reply




MultiQuote





|