I'm working on a simple number guessing game where the computer creates a random number between 1 and 1000, then the user has to guess it. To give the user clues I am changing the bounds with each guess. This means that when the user guesses a number, the program compares it to the random number to see which is bigger. If the random number is bigger, the lower bound will be changed to the user's guess but if the random number is smaller then the higher bound will be changed. I did this by saving both bounds as variables.
Unfortunately, the code doesn't run and gives me an error message that reads "error CS1003: Syntax error, ',' expected". I have tested the variables on their own and I have tested them in the while loop which leads me to believe that the changing of the boundaries to the user's guess is what's causing the issue.
Edit - my error was on line 24
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
//declare variable before loop
int userGuess;
//random number
Random r = new Random();
int randomInteger = r.Next(1, 1001);
//declare upBound and lowBound
int lowBound = 1;
int upBound = 1000;
//loop
while (userGuess != randomInteger)
{
// ask the user to guess the number
Console.WriteLine("I've picked a random integer between " + lowBound + " and " + upBound + ". What is it?");
//save user input
string userGuessStr = Console.ReadLine();
//is the user input an integer
bool num = int.TryParse(userGuessStr, out userGuess);
//if number is an integer
if (num)
{
//if userguess is in bounds
if (userGuess<1001 + userGuess>0)
{
//if userguess is lower than number
if (userGuess<randomInteger)
{
int lowBound = userGuess;
}
//if userguess is higher than number
if (userGuess>randomInteger)
{
int upBound = userGuess;
}
}
// if user guess is out of bounbds
else
{
Console.WriteLine("I'm sorry but that is out of the bounds of an acceptable answer. Please try putting in a number that is between 1 and 1001");
}
}
//if number is an integer
else
{
Console.WriteLine("I'm sorry but that isn't an integer. Please try again");
}
}
//congrats message
Console.WriteLine("Congratulations, you were correct. The answer was" + rInt + ".");
}
}
}
Any help would be appreciated.