Puts("Guess a number between 1 and 100") * could be negative, so ensure it's positive */ Getrandom(&randval, sizeof(int), GRND_NONBLOCK) * pick a random number from 1 to maxval */ So, instead of hard-coding the function to pick a random number between 1 and 100, write the function to pick a random number between 1 and some integer value maxval: #include When writing functions, good programmers try to make them flexible, so they can reuse them to solve slightly different problems. Start the "Guess the number" game by writing a function to pick a random number. So, I thought I'd follow up by writing a "Guess the number" game in C. Since then, I've heard from many people who are learning C programming by following it. Over the summer, I recorded a video series to teach people how to write programs in the C programming language. What's great about a "Guess the number" game is that it exercises several programming concepts: how to use variables, how to compare values, how to print output, and how to read input. eBook: An introduction to programming with Bash.Try for free: Red Hat Learning Subscription.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |