Advertisement
Fox_McCloud77

CSLight_Program_With_Password_HW

Feb 12th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CSLight_Program_With_Password_HW
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.OutputEncoding = Encoding.UTF8;
  14.  
  15.             string password = "123456";
  16.             string userInput;
  17.             int tryCount = 3;
  18.  
  19.             for (int i = 1; i <= tryCount; i++)
  20.             {
  21.                 Console.Write("Введите пароль: ");
  22.                 userInput = Console.ReadLine();
  23.  
  24.                 if (userInput == password)
  25.                 {
  26.                     Console.WriteLine("Доступ к тайному сообщению разрешен!");
  27.                     break;
  28.                 }
  29.                 else if (i == 3)
  30.                 {
  31.                     Console.WriteLine("Доступ запрещен!");
  32.                 }
  33.                 else
  34.                 {
  35.                     Console.WriteLine($"У вас осталось попыток: {tryCount - i}");
  36.                 }
  37.             }
  38.             Console.ReadKey();
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement