Hi all! I am new to C#. First steps. I want to write a simple console application that asks the user to enter the password. I want to limit the attempts. For example after three failed attempts console will write "you've failed".
Best wishes
Below code gives the user infinite rights to try:
string Pass= "";
do
{
Console.Write("Enter Password : ");
Pass= Console.ReadLine();
} while (Pass!= "9999");
Console.WriteLine("Success!...");
Console.ReadKey();

Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Nov 8, 2015, 9:27 AM EST
int count = 0; do { if(count > 2) { // 3 Attempts made Console.WriteLine("You've failed"); break; // Get out of the loop } Console.Write("Enter Password : "); Pass= Console.ReadLine(); if(Pass == "9999") { Console.WriteLine("Success!"); break; // Get out of the loop } count++; // Increment } while (Pass!= "9999");Pisi Can21 reputationPosted Nov 8, 2015, 9:41 AM EST