People in this thread are talking about computer memory management and the like. Meanwhile, I’m still making little casino like games with the absolute basic logic.
Good work. I'm definitely seeing improvement
No you're not. You're just learning. Everyone has to start somewhere. Beating yourself up does you no favors.
Besides,
exceptional individuals don't take up learning C. They go for Javascript and use it for
everything. You're already way above them in terms of understanding and ability. I have seen all sorts of
exceptional individuals in my time teaching and tutoring, and you sir are not one of them.
I didn’t know you could use define like that.
C's preprocessor is really quite powerful. I often find myself missing it when I use other languages. There's a debate about using
#define for constants over const types, and both have their merits for different cases, but I use
#define 99% of the time. The logic starts getting into how compilers and shit work, so I'll leave that for later.
As mentioned above, make sure your constants have descriptive names, and use underscores to separate out words in the names when needed. It's good practice to define constants up there for readability and easy modifications, but giving them good names is crucial. You
can use the more advanced preprocessor macros like the example you were given, but even basic ones like you defined in your program are seriously handy when used effectively.
Most of the other stuff was covered, so I'll simply add that the
if (bal < 1.0) bit and other similar boundary checks should almost always appear at the start of the loop instead of near the end as a rule of thumb. It helps tremendously with preventing introducing overspending problems and out-of-bounds memory reads as you add more stuff later on. Good programming is all about accounting for future poor decision making, both by the programmer and the end users.
Be a bit careful with function macros, because if you do something like putting a rand() call in there, it may be included (and called) many times and different parts of your function will end up with different values from the same "variable". These aren't real functions, they just substitute text into another piece of text and it ends up looking like a function call. Whenever you see a complex expression inside of a macro function, just think a little bit about how it would interact. Most of the time it'll be fine but if you call anything really expensive or non-deterministic your shit will be fucked.
Excellent point. As a rule, always encapsulate more complex macros to avoid issues with braces and semicolons, and never use macros for anything that significantly affects control flow.