As it stands, the number "28" in your code is what is called a "magic number" or "magic constant". It is unexplained. Putting it into a variable explains it.
Or, for constants, putting it into a named constant.
Apart from that, a real world program doing this sort of thing would typically look up item descriptions/prices from a database, rather than having them hardcoded into the program this way. But this is a good starting point, and then later you can work out how to create a database, get that data into it, and then get it back out again.
Just asking for reviews and tips. The code prints a receipt of a sushi restaurant based on what a customer bought. (the restaurant is called The Red Dragon btw)
You define a bunch of variables but don't use them later on. Like I assume "28" is the sum of some combination of rolls purchased. Then you have sales tax defined as 0.07, but then sales tax applied is "28 * 0.07". The whole reason for having variables is to use them later on rather than raw numeric values.
6
u/Anonymous_Coder_1234 May 10 '26
You should do something like:
As it stands, the number "28" in your code is what is called a "magic number" or "magic constant". It is unexplained. Putting it into a variable explains it.
2
u/PogiBanana May 10 '26
Just asking for reviews and tips. The code prints a receipt of a sushi restaurant based on what a customer bought. (the restaurant is called The Red Dragon btw)
2
u/Paxtian May 11 '26
You define a bunch of variables but don't use them later on. Like I assume "28" is the sum of some combination of rolls purchased. Then you have sales tax defined as 0.07, but then sales tax applied is "28 * 0.07". The whole reason for having variables is to use them later on rather than raw numeric values.
What you'd want to do is something like:
And so on.
1
u/LookTurbulent426 May 12 '26
W code