Join Dan Gookin for an in-depth discussion in this video Solution: Lotto simulation, part of C: Data Structures, Pointers, and File Systems.
(upbeat music) … - [Narrator] I hope you enjoyed this challenge. … As with any programing problem, … the lotto simulation can be solved in several ways. … Here's my solution. … The key to this challenge … is to find a way to track the lotto balls already drawn. … The method I use … is to create and array lotto ball here at line 10, … which has the same number of elements … as the number of balls, or numbers available to draw, … set as the constant expression count defined at line five. … The array is initialized with all zeros … in the for loop at line 16. … The while loop at line 21 draws the balls. … It plucks a random number into variable B at line 24. … Then it compares that array element number … with zero at line 26. … So if the element is zero, the ball hasn't been drawn. … It's a valid number. … At line 29, the element is set to one, … which prevents it from being drawn again, … and the draw index is incremented, … meaning there's one less number to draw. … The loop repeats. …
- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
1. Arrays and Structures
2. Characters and Strings
4. Files and the Operating System
5. The Interesting and Extraordinary
Next steps1m 52s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.