C#:
uses System;
public class program
{
public static void Main ()
{
Random randomerare = new Random ();
was randomNumber = random number. Next (1,101);
int-counter = 1;
var maxGuesses = 8;
for (int i = 0; i <8; i ++) / * First used the variable “i” as my counter
but when I did, I got that after a guess that I had all the guesses left.
Set "i" to 1 instead of 0 but then I came to my first if I set immediately and the program ended.
What can I do if I want to use "i" correctly.
* / {
// while (counter! = maxGuesses)
Console.WriteLine ("Guess a number between 1-100:");
var userGuess = Convert.ToInt32 (Console.ReadLine ());
if (counter == maxGuesses)
{
Console.WriteLine ("Game over! You've finished your 8 guesses!");
break;
}
om (userGuess> randomNumber)
{
/ * if (randomNumber> 70 && userGuess> 70)
{
} * /
Console.WriteLine (userGuess + "Is too high, try again ..." + "\ nYou have" + (maxGuesses counter) + "guesses left ...");
counter ++;
}
otherwise if (randomNumber> userGuess)
{
Console.WriteLine (userGuess + "Is too low, try again ..." + "\ nYou have" + (maxGuesses counter) + "guesses left ...");
counter ++;
}
Other
{
Console.WriteLine (userGuess + "Is the correct number!" + "\ NYYou guessed {0}" + counter + "times!");
break;
}
}
}
}
Last edited by a moderator: