after we have re asigned the variable meal to meal + meal * tax why would we add meal to meal again?
meal = meal + meal * tax
Well, we want to update the meal variable. What should the new value be? The cost of the meal + the tax (tax is meal cost times tax)
I was initially wondering the same thing. Basically the calculation you are doing is meal = meal + (meal * tax).
Well the tax will be something like 3% or something around, I assume. So if the meal costs 40$ and you multiply it with 0.03, you will have the tax for the meal only, but not how much you have to pay actually.
meal (price of the meal at the cafeteria or whatever) = 40$
tax = 40$ * 0.03 = 1.2$
meal (price you have to pay) = meal + tax = 41.2$
Makes sense, right?
I'm confused as to why the total came out at 54.63, by the looks of line 7
meal = meal + meal * tax shouldn't that be two meals?
No, because of order of operation. Multiply is before add/sum. Let's break it down:
we are going to assign a new value to our variable meal.
then because of order of operations, multiply is first:
meal * tax
which will give you the tax, which we then add to the meal costs:
meal + (meal * tax)
i put it in brackets, because we already calculated it. So now, we updated our variable and included the taxes