public class Program // simple atm system
{
public static void Main()
{
// setting account variables, a balance, pin, and usernmae
int balance = 500;
int pin = 1234;
string user = "Jack";
// setting account attempts
int Attempts = 1;
int AttemptsLimit = 3;
bool auth = false;
// while attempts are less than the attempt limit and auth is false loop:
while (Attempts < AttemptsLimit && auth == false)
{
//input pin
Console.WriteLine("Enter pin: ");
int AttemptPin = Convert.ToInt32(Console.ReadLine());
// if attempted pin is the correct pin
if (AttemptPin == pin)
{
//execute the method
Console.WriteLine("Welcome, " + user);
auth = true;
int result = withdraw(balance, 200);
Console.WriteLine("test "+result);
}
// if attempted pin is not equal to pin
else if (AttemptPin != pin)
{
Console.WriteLine("Error \n");
Console.WriteLine("You have made "+Attempts+" attempt");
// add onto attempts made
Attempts++;
}
else
{
Console.WriteLine("Error: \n you have run out of attempts");
}
}
// keep the CLI running
Console.ReadLine();
}
static int withdraw(int TheBalance, int WithdrawAmount)
{
TheBalance = TheBalance - WithdrawAmount;
Console.WriteLine(TheBalance);
return TheBalance;
}
}