How to prevent random number game from saying things at the wrong time

• Question

• I'm trying to make a random number guessing game for the command prompt and it's working out okay, but whenever the game restarts after user wants to play again, the game keeps saying, "Want to play again? 'Y' or 'N': Y Wrong guess. Number is too high. Pick a lower number." or "Want to play again? 'Y' or 'N': Y Wrong guess. Number is too low. Pick a higher number. " on the same line.
How do I prevent the game from thinking the Y or N question is a guess?

Code:

using System;

using static System.Console;

namespace Guessing Game

{

class Program
{
static void Main(string[] args)
{
Random RandomClass = new Random();
int randomNumber;
int guess;
string yesOrNo;
string upperYesOrNo;
int guessAmount = 0;
const int MIN = 1;
const int MAX = 10;
//random number will be >= MIN and < MAX
randomNumber = RandomClass.Next(MIN, MAX);

Write("Guess a number from 1 to 10: ");

do
{
randomNumber = RandomClass.Next(MIN, MAX);
do
{
if (guess != randomNumber && guess < randomNumber)
{
guessAmount++;
WriteLine("Wrong guess. Number is too low. Pick a higher number. ");
Write("Guess a number from 1 to 10: ");
}
else if (guess != randomNumber && guess > randomNumber)
{
guessAmount++;
WriteLine("Wrong guess. Number is too high. Pick a lower number. ");
Write("Guess a number from 1 to 10: ");
}
} while (guess != randomNumber);

if (guess == randomNumber)
{
WriteLine(\$"Correct! The number was {randomNumber}.");
WriteLine(\$"It took you {guessAmount} guesses.");
}
Write("Want to play again? 'Y' or 'N': ");
upperYesOrNo = yesOrNo.ToUpper();

if (upperYesOrNo == "Y")
{
Write("Guess a number from 1 to 10: ");
}
} while (upperYesOrNo == "Y");

//Debug pause
WriteLine("Press any key to continue...");
}
}
}
Tuesday, October 16, 2018 1:28 AM

• Greetings Rainbow.

You need to reset the guess and guessAmount.

```         Write("Want to play again? 'Y' or 'N': ");