I need help with a random selection and elimination problem in C | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

I need help with a random selection and elimination problem in C

From the numbers 1-10, we're to randomly select a number. Then eliminate that number from being randomly picked again. So on our second random selection, we cannot select the first number again. So if we pick 7 the first time, we can't pick it the second time. And if we pick 5 the second time, we can't pick 5 or 7 the third time. And so on until all numbers have been picked. I've tried but I don't know how to eliminate the choices. I can generate the 10 numbers but I can't eliminate https://code.sololearn.com/cZVF003kblYC/?ref=app

4th Nov 2020, 8:45 PM
Sekiro
Sekiro - avatar
6 Respuestas
+ 3
Have you tried something?
4th Nov 2020, 9:37 PM
Davide
Davide - avatar
+ 3
Id suggest learning a little more of C, maybe even finishing the whole course on here its pretty short
4th Nov 2020, 10:13 PM
Roderick Davis
Roderick Davis - avatar
+ 3
Terver Torvenda it's nice to see some code from you!🤗 First of all your program generates numbers from 0 to 9. To generate numbers from 1 to 10 you need to do: randd = rand() % 10 + 1; Now in order to make the program avoid previously generated numbers you need indeed to keep track of which numbers you have already generated. How can you store these numbers? Do you know about arrays? If not, please learn about them and then come back to improve your program.
4th Nov 2020, 11:17 PM
Davide
Davide - avatar
+ 1
NotAPythonNinja since it seems he doesn't know about arrays, chances are he doesn't know that an array declared as global variable is initialised to 0 by default. It may be worth to be said.
4th Nov 2020, 11:37 PM
Davide
Davide - avatar
+ 1
Davide thank you soo much. I will go and read up on arrays. Much appreciation for the correction to my code to generate the random numbers. Thanks a lot
5th Nov 2020, 12:46 PM
Sekiro
Sekiro - avatar
+ 1
NotAPythonNinja thanks a lot. I'll read up on arrays to understand your code better. Thanks again
5th Nov 2020, 12:47 PM
Sekiro
Sekiro - avatar