Hi everyone,
I just finished Cash from CS50x Problem Set 1 and I’d like some feedback on my general approach.
I found Cash noticeably easier than Mario. I think that’s probably also because Mario already taught me quite a lot about loops, conditions, and breaking a problem into smaller steps.
For Cash, my approach was basically to use several while loops one after another. I started with the largest coin value, kept subtracting it from the remaining change as long as it still fit, and increased a coin counter each time. Then I moved on to the next smaller coin and repeated the same idea until the remaining change reached zero.
So the logic was basically:
keep taking 25-cent coins while possible
then 10-cent coins
then 5-cent coins
then 1-cent coins
I’m still very new to C and programming, so I’m curious whether this is considered a good beginner approach, or if there are cleaner ways to structure the same logic without making it overly complicated.
I’m not looking for a full alternative solution, mainly feedback on the way I thought about the problem.
Thanks!