Answer to Question #298337 in C# for Zyke

Question #298337

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.

1
Expert's answer
2022-02-16T04:45:30-0500
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);
            
 
        }
    }

   
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS