Make a program that will ask the student to enter a PIN Code. Each year level has its own PIN Code. If
the entered PIN Code is correct a message “Access Granted! Welcome yr_lvl Student.” will appear, if it is
wrong a message “Invalid PIN! Access Denied” will appear. The program will terminate after three (3)
incorrect attempt.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int attempt = 0;
bool exit = false;
Dictionary<string, int> yearsPin = new Dictionary<string, int>();
yearsPin.Add("1233", 2019);
yearsPin.Add("4747", 2020);
yearsPin.Add("3535", 2021);
yearsPin.Add("8686", 2022);
do
{
Console.WriteLine("Please enter PIN Code");
string pin = Console.ReadLine();
if (yearsPin.ContainsKey(pin))
{
Console.WriteLine("Access Granted! Welcome {0} Student.", yearsPin[pin]);
exit = true;
Console.ReadKey();
}
else
{
Console.WriteLine("Invalid PIN!Access Denied");
attempt++;
}
if (attempt == 3)
exit = true;
} while (exit != true);
}
}
}
Comments
Leave a comment