Advertisement
TwinFrame

Clight_15_EnterPassword

Mar 22nd, 2023 (edited)
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Clight_15
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             string password = "game";
  10.             string secretMessage = "Hello, world!";
  11.             string userInput;
  12.             int attemptsCount = 3;
  13.  
  14.             for (int i = 1; i <= attemptsCount; i++)
  15.             {
  16.                 Console.Clear();
  17.                 Console.Write("Введите пароль: ");
  18.                 userInput = Console.ReadLine();
  19.                 Console.Clear();
  20.  
  21.                 if (userInput == password)
  22.                 {
  23.                     Console.Write($"Секретное сообщение: {secretMessage}\n");
  24.                     Console.Write("Для выхода нажмите любую клавишу");
  25.                     Console.ReadKey();
  26.                     return;
  27.                 }
  28.                 else
  29.                 {
  30.                     Console.WriteLine($"Пароль введён не верно. Осталось попыток: {attemptsCount - i}.\n");
  31.                     Console.Write("Для повторного ввода пароля нажмите любую клавишу");
  32.                     Console.ReadKey();
  33.                 }
  34.             }
  35.  
  36.             Console.Clear();
  37.             Console.WriteLine("Попытки ввода пароля истекли.\n");
  38.             Console.Write("Для выхода нажмите любую клавишу");
  39.             Console.ReadKey();
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement