• Создать Код На Языке C#:

    Создать программу, в которой компьютер загадывает случайное число от 1 до 10 у пользователя 3 попытки отгадать правильное, если пользователь отгадывает то выводиться соответствующее сообщение, в конце выводится загаданное число.
    Снимок С первой нароботкой Снизу!

    question img

Ответы 1

  • Ответ:

    using System;

    namespace ConsoleApp4

    {

       class Program

       {

           static void Main()

           {

               int attempts = 1;

               Random r = new Random();

               int x = r.Next(11);

               Console.WriteLine("Ok. I made a guess. Now you have 3 attempts.");

               for (int i=0; i < 3; ++i)

               {

                   Console.WriteLine($"Attepmt #{attempts}");

                   if (int.Parse(Console.ReadLine()) == x)

                   {

                       Console.WriteLine($"Congrutialations! You got it!It really was number: {x}Attempts passed: {attempts}Try again? y/n");

                       if (Console.ReadLine() == "y")

                       {

                           Console.Clear();

                           Main();

                           return;

                       }

                       return;

                   }

                   Console.WriteLine("Nope.");

                   attempts++;

               }

               Console.WriteLine($"You lose.It was: {x}Try again? y/n", x);

               if (Console.ReadLine() == "y")

               {

                   Console.Clear();

                   Main();

                   return;

               }

           }

       }

    }

    • Автор:

      chana
    • 6 лет назад
    • 0
  • Добавить свой ответ

Еще вопросы

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years