Simply return once after setting value of guessed
class GuessNumber
{
public int number;
public Random Rand;
public string randNum()
{
int randomNumber = Rand.Next(1, 9);
string guessed = "";
while (guessed != "correct")
{
if (randomNumber > number)
{
guessed = "too low";
}
else
if (randomNumber < number)
{
guessed = "too high";
}
else
{
guessed = "correct";
}
}
return guessed;
}
}