0
random numbers in array check they don't repeat
I have an array of variable length that either the user can enter a set of numbers between 1 and 9 or get a random set of numbers between 1 and 9. I need to make sure that either way the numbers do not repeat. I know I need a loop just not sure which one I should use. I will post the code I have for the user entering their own set of numbers as the first comment if that helps any.
4 Answers
+ 1
Here you go. You can't try it here on playground. You have to do it on your computer.
https://code.sololearn.com/cmkIvyJtdwcz/?ref=app
0
for(int aaa = 0; aaa < 4; aaa++)
{
Console.Write("Pick a number between 1 and 9, numbers cannot repeat : ");
string playernum = Console.ReadLine();
while (!int.TryParse(playernum, out playerNum[aaa]) & playerNum[aaa] < 1 | playerNum[aaa] > 9 )
{
Console.Write("You must enter a number between 1 and 9, numbers cannot repeat : ");
playernum = Console.ReadLine();
}
}
0
Thank you so much Joel it worked perfectly
0
Glad I could help. đ