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.

5th Sep 2018, 5:09 PM
David Aseltine
David Aseltine - avatar
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
5th Sep 2018, 8:07 PM
Joel Keleta
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(); } }
5th Sep 2018, 5:12 PM
David Aseltine
David Aseltine - avatar
0
Thank you so much Joel it worked perfectly
6th Sep 2018, 2:08 AM
David Aseltine
David Aseltine - avatar
0
Glad I could help. 🙂
6th Sep 2018, 4:05 PM
Joel Keleta