Hi I am trying to make a mastermind game where I having the user guess a number sequence between 4-10 instead of colours but for some reason my GetRandomNumberCount and my Gener
That's because they don't return a value. For example GetRandomNumberCount has Int
set as its return type, but has no return statement. If you want to return nothing set the return type to void. Using that as an example
public static int[] GetRandomNumberCount()
{
//Create the secret code
Random RandomClass = new Random();
int first = RandomClass.Next(1, 5);
int second = RandomClass.Next(1,5);
int third = RandomClass.Next(1,5);
int forth = RandomClass.Next(1,5);
Console.WriteLine ("You are playing with M@sterB@t");
Console.WriteLine ("Bot Says : You Go First");
Console.WriteLine("Game Settings ");
Console.WriteLine("The Game Begins");
//This is where you would return a value, but in this case it seems you want to return an array of ints
//Notice how I changed the return type of the method to Int[]
int[] numbers = new int[4];
numbers.Add(first);
numbers.Add(second);
numbers.Add(third);
numbers.Add(fourth);
//This is the actual return statement that your methods are missing
return numbers;
}
regardless of whether you actually want to return an int array is moot though, Im only guessing. The real take away is that the int[]
in
public static int[] GetRandomNumberCount()
declares a return type meaning you need a a return statement.
You are getting that error cause your method signature says it returns a int
but your are not returning anything. What I see is, you meant to have a method with void
return type like below since you are just printing the lines
public static void GetRandomNumberCount()
{
//Create the secret code
Random RandomClass = new Random();
int first = RandomClass.Next(1, 5);
int second = RandomClass.Next(1,5);
int third = RandomClass.Next(1,5);
int forth = RandomClass.Next(1,5);
Console.WriteLine ("You are playing with M@sterB@t");
Console.WriteLine ("Bot Says : You Go First");
Console.WriteLine("Game Settings ");
Console.WriteLine("The Game Begins");
}