This month’s Exercise was originally how to create a structure pointer, fill it with data, and write that data to a file. It’s a procedure fraught with traps and peril. What’s even more challenging is when you’re presented with this type of code and it doesn’t work, but it’s your job to fix it.
Continue reading
Category Archives: Exercise
Ranking Scores
In your fancy, new game, the program dutifully track players and their scores. When the game is over, or at the end of a round, the players not only want to know their scores, but where each sits in the overall ranking. That process takes a bit more coding than just spitting out the scores.
Continue reading
When You Need a Function
I believe two reasons exist for creating functions. The first is repetition; when you have a chunk of code that duplicates several times, it’s best to shove it off into a function where it can be called repeatedly. The second reason is readability.
Continue reading
The Curse of Typecasting
In the C language, it’s called typecasting: A variable of one type — for an instant — masquerades as another variable type. In Hollywood, however, it’s a curse: The typecast actor can play roles other than the one he’s famous for creating. That sucks.
Continue reading
Take Your Turn
The game of Tic-Tac-Toe, also called Noughts and Crosses, provides a fertile field to plow for any budding programmer. It involves a matrix (array), logic, decisions, and all sorts of fun. If you haven’t yet coded your own Tic-Tac-Toe game, I urge you to do so, but that’s not the topic for this month’s Exercise.
Continue reading
Your Card is Valid
When you type a credit card number on a website, or scan the card into a physical device, a quick calculation is performed to ensure that the card number is valid. This check happens before the bank is contacted to verify the account and the amount. The technique used to perform the quick calculation is known as the MOD 10 algorithm.
Continue reading
Tally the Digits
The programming adventure is full of interesting twists and turns, and with each new puzzle comes multiple opportunities to flex your coding skills and devise new solutions. For this month’s Exercise, the task is to take an integer value and add up all its digits. The mathematical term for this operation is a digit sum.
Continue reading
Find the Best Size Container
Not everything in the real world appreciates the holy computer numbers. These are binary values that parallel the powers of 2: 1, 2, 4, 8, 16, 32, 64, and so on.
A common computer puzzle is how to allocate storage specific to those holy numbers, especially when the sizes of items that you’re working with don’t exactly line up to a specific holy computer number.
Continue reading
Off to the Races!
Computer games were simple back in the early days. Output was printed on a teletype or displayed on a text-only CRT. Input wasn’t interactive or real-time. These games were fun to play back then, but are kind of lame now. They still exist with regards to simple programming exercises. In fact, you can pound out a older type computer game in a few minutes if you know the basics of the C language.
Continue reading
Read a Percentage Value
Here’s a thought experiment for you: How can you prompt a user to properly input a percentage value?
Continue reading