I'm new to C# and I'm struggling a bit with loops. For this one, I'm trying to use the 'for' loop. I have tried various options - for, while loops, but I wasn't able to reach the desired result.
For this one, the says I lost, even if I "guessed" the number.
{
var random = new Random();
int random2 = Convert.ToInt32(random.Next(0, 10));
Console.WriteLine(random2);
for (var i = 4; i <= 4; i++)
{
Console.WriteLine("Please enter a number from 0 to 10:");
var input = Convert.ToInt32(Console.ReadLine());
if (input != random2)
{
Console.WriteLine("You have {0} tries left.", i - 1);
continue;
}
if (input != random2)
{
Console.WriteLine("You have {0} tries left.", i - 1);
continue;
}
if (input != random2)
{
Console.WriteLine("You have only {0} try left!!", i - 1);
continue;
}
if (input == random2)
{
Console.WriteLine("You lose!!!");
break;
}
if (input == random2)
{
Console.WriteLine("You have won!!!!!");
break;
}
}
}
What I'm trying to do: write a program that picks a random number between 1 and 10 and gives the user 4 chances to guess it. However, I want to make the console print the remaining number of tries and print a different message when the user is on their last try.
Let's implement from scratch step by step:
attemptinstead ofi)