Hey everyone! I've been learning C++ for about a month now and just finished chapter 13, where I was introduced to structs. Since none of my friends work in computer science, I was hoping to get some feedback on the code I've written for a simple coffee ordering system. My goal is to eventually do some game development with Unreal Engine as a hobby.
In my code, I incorporated a few concepts like const references, structs for data grouping, and tried to minimize magic numbers. I also learned about operator overloading and attempted to implement it.
Here's what I'd love feedback on:
1. Am I using const references correctly? Am I missing them or perhaps overusing them?
2. I noticed my functions take a lot of parameters, which could become unwieldy if I add more coffee types. Is there a better design for that?
3. I'm not very comfortable with operator overloading yet and find myself second-guessing when I should use it. Any advice on that?
I'm open to any suggestions on how to improve code quality and style. Thanks a ton in advance!
3 Answers
Here are a few general pointers:
1. It sounds like you haven’t learned about standard containers yet. Once you do, re-evaluate your code because there might be opportunities to simplify.
2. As a style tip, I think you're overusing the uniform initialization syntax—sometimes a simple `=` would suffice.
3. Be cautious with using floating-point types for currency; typically, you’d use integers to represent the smallest unit, like cents, to avoid precision issues.
Have you thought about sharing your code on a platform like GitHub or Bitbucket? It makes it easier for people to provide feedback and comment on specific parts of your code.
I'm not a C++ expert, but I do recall that arrays might be what you’re looking for in terms of making your functions more scalable. Instead of many separate parameters for each coffee type, consider using an array of CoffeeData objects. It’ll allow you to handle multiple coffees neatly and loop through them easily.
Concerning operator overloading, don’t stress about it too much right now. It's a useful feature but focusing on mastering the basics of C++ might serve you better at this stage!
Thanks for the insight! I'm looking forward to learning about arrays—as I just finished chapter 13 and will reach arrays in chapter 16. I'll keep your advice about operator overloading in mind!
Exactly! Also, consider reading up on how to handle user input with arrays, which will help if you want to extend your coffee options in the future.

Good idea! I thought the code was short enough to post here, but I'll definitely set up a GitHub account for future projects!