15,901,666 members
1.00/5 (1 vote)
See more:
Hello, I'm making a number guessing game in C# for homework. When I run it, if the guess is lower or higher than the random number, it just loops "Guess higher" or guess lower". Any help would be appreciated.

```  using System;

namespace Lab7
{
class Program
{
static void Main(string[] args)
{
//Problem1();
//Problem2();
Problem3();
//Problem4();
//Problem5();
//Problem6();
//Problem7();
//Problem8();
//Problem9();
//Problem10();

static void Problem3()
{
Random random = new Random();
int numNums = 2;
int GuessCount = 1;
int current = 0;
Console.WriteLine("Enter amount of numbers to guess from (100 for 1 - 100) ");
int randy = random.Next(1, numNums);
if (current == randy)
{ Console.WriteLine("Good job!  Guessed in {0} guesses!", GuessCount); }

while (current != randy)
{

if (current > randy)
{
Console.WriteLine("Guess lower.");
GuessCount++;
continue;
}
if (current < randy)
{
Console.WriteLine("Guess higher.");
GuessCount++;
continue;
}
}```

What I have tried:

We recently finished with Python, now we're trying problems we solved in Python in C#. I have no clue what to do here lol
Posted
Updated 28-Nov-21 13:04pm
v3

## Solution 1

Figured it out!

```static void Problem3()
{
Random random = new Random();
int numNums = 2;
int GuessCount = 1;
int current = 0;
Console.WriteLine("Enter amount of numbers to guess from (100 for 1 - 100) ");
int randy = random.Next(1, numNums);

while (current != randy)
{
if (current == randy)
{ Console.WriteLine("Good job!  Guessed in {0} guesses!", GuessCount); }
if (current > randy)
{
Console.WriteLine("Guess lower.");
GuessCount++;
continue;
}
if (current < randy)
{
Console.WriteLine("Guess higher.");
GuessCount++;
continue;
}
}```

PIEBALDconsult 28-Nov-21 23:51pm
Grelm 29-Nov-21 1:53am
Why not? I was going to just delete it, but it let me enter the solution myself. And I figure if someone else is having similar issues then they might be helped by my solution.
PIEBALDconsult 29-Nov-21 7:59am
Certainly, but it's better to update the question.