Earlier this week i created a program that ask for a passcode in the form of user input. The idea was that you have a certain amount of tries to enter the passcode before the system locks you out. This was my first time using loops. Below is the code that i used.
namespace Passcode
{
class Passcode
{
static string strPasscode = "pinkmonkeybutt";
public static void Main(string[] args)
{
string strInput;
//counting variable//
int i = 0;
do
{
Console.Write("What is the passcode: ");
strInput = Console.ReadLine();
if (strInput == strPasscode)
{
Console.WriteLine("You have gained access");
}
else
{
Console.WriteLine("Access Denied");
}
i++;
Console.WriteLine("try #:"+i);
}
while ((strInput != strPasscode) &&amp;amp; i < 3);
if (i == 3 && (strInput != strPasscode))
{
Console.WriteLine("You have been locked out bitches!");
}
else
{
Console.WriteLine("Welcome to the system.");
}
Console.ReadLine();
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment