lovelyvook

Unit_14

Mar 31st, 2024
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Ijunior
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string userPassword;
  10.             string userInput;
  11.             int totalAttempts = 3;
  12.  
  13.             Console.Write("Установите пароль: ");
  14.             userPassword = Console.ReadLine();
  15.  
  16.             for (int i = totalAttempts; i > 0; i--)
  17.             {
  18.                 Console.Write($"Введите пароль, у вас {i} попыток: ");
  19.                 userInput = Console.ReadLine();
  20.  
  21.                 if (userInput == userPassword)
  22.                 {
  23.                     Console.WriteLine("Секретное сообщение: Дарт Вейдер твой отец");
  24.                     break;
  25.                 }
  26.                 else if (userInput != userPassword && i > 1)
  27.                 {
  28.                     Console.WriteLine("Неверно, попробуй еще раз");
  29.                 }
  30.                 else
  31.                 {
  32.                     Console.WriteLine("Потрачено");
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment