jeudi 11 novembre 2021

How to make my program say that I'm close or far from the answer and then to input it again? C#

Here I have the program that selects random number for me to guess. How can I make it now to say that number is close or far away from original random selected by the program?

using System;


namespace higherlower_guesser
{
class Program
{
    static void Main(string[] args)
    {


        Random rnd = new Random();
        int randomNumber = rnd.Next(0, 100);


        bool answerCheck = false;
        int guessAttempts = 0;

        
        while (answerCheck == false)
        {
            Console.Clear();
            Console.WriteLine("Take a guess.");
            guessAttempts++;
            int enteredValue = int.Parse(Console.ReadLine());
            if (enteredValue == randomNumber) 
            {
                Console.WriteLine("Congratulations, the number in mind is {0}. You've had {1} attempts", randomNumber, guessAttempts);
                answerCheck = true;
            }
          }
        }
      }
    }

Aucun commentaire:

Enregistrer un commentaire