One of these days I’ll actually know how to program c++ pretty well, and when that happens, I plan to write some kickass software. But when that happens, I figured it would be pretty amusing to look back at my very first c++ program (besides the mandatory “Hello World!” app).
This was our first assignment in Computer Science 210, page 98, #15 in Problem Solving, Abstraction & Design Using C++ (5th Edition). To quote:
Write a program that dispenses change. The program should read the amount of the purchase and the amount paid and then display the number of dollars, quarters, dimes, nickels, and pennies given in change.
Actually if you keep reading, they tell you the wrong way to do it, as a “hint”. Jerks.
But notwithstanding, this is what I wrote:
I promise, there was lots more whitespace in the actual program. WordPress is just being stupid. Here's the file for download: ChangeDispenser.cpp.
Warning: Don't cheat off me.
UPDATE 10-19-09: Fixed a bug in how pennies were calculated.
UPDATE 11-01-09: Fixed formatting / lack of whitespace.








Post a Comment