I am learning c# as a beginner and making a program that gives the user a random number from a dice until it gets a six. Here is my complete code:
using System;
class HelloWorld {
static void Main() {
Random numberGen = new Random();
int roll = 0;
int attempts = 0;
Console.WriteLine("Press enter to roll the die");
while (roll != 6) {
Console.ReadKey();
roll = numberGen(1, 7);
Console.WriteLine("You rolled " + roll);
attempts++;
}
Console.WriteLine("It took you " + attempts + " to roll a six");
Console.ReadLine();
}
}
What am I doing wrong and how can I debug it?
numberGen(1, 7)should benumberGen.Next(1, 7). Refer to the documentation for more. Side note: If you want the user to "press enter", useConsole.ReadLine()instead ofConsole.ReadKey(). The latter will accept any keystroke, not just the Enter key.