Advertisement
TeT91

ДЗ Программа под паролем

May 10th, 2024 (edited)
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string password = "qwerty";
  10.             int attempsCount = 3;
  11.             bool isAccessClosed = false;
  12.  
  13.             string secretMessage = "Секретное сообщение";
  14.  
  15.             while (isAccessClosed == false)
  16.             {
  17.                 Console.WriteLine("Введите пароль");
  18.                 string userInput = Console.ReadLine();
  19.  
  20.                 if (userInput == password)
  21.                 {
  22.                     Console.WriteLine(secretMessage);
  23.                     break;
  24.                 }
  25.                 else
  26.                 {
  27.                     attempsCount--;
  28.  
  29.                     if (attempsCount > 0)
  30.                     {
  31.                         Console.WriteLine($"Неверный пароль. Осталось {attempsCount} попыток");
  32.                     }
  33.                     else
  34.                     {
  35.                         Console.WriteLine("Доступ зарпещен");
  36.                         isAccessClosed = true;
  37.                     }
  38.                 }
  39.             }
  40.  
  41.             Console.ReadLine();
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement