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

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

Приложения:

Ответы

Ответ дал: savap0
0

Ответ:

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!nIt really was number: {x}nAttempts passed: {attempts}nTry again? y/n");

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

                   {

                       Console.Clear();

                       Main();

                       return;

                   }

                   return;

               }

               Console.WriteLine("Nope.");

               attempts++;

           }

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

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

           {

               Console.Clear();

               Main();

               return;

           }

       }

   }

}

Вас заинтересует