There is a problem with this exercise in that it won't accept my correct answer of of meal*(tax + 1)
The exercise is quite rudimentary in that we add tax to the meal, and calculate the tip against that amound. Some learners want the tip to only apply to the meal, not the tax. It's only a few cents, but the SCT will only accept the expected amount. If there is a disagreement between your method and the one expected, you will get a fail.
So long as we have calculated tax as,
6.75 / 100
then the following should satisfy the first step...
meal *= 1 + tax
The rudimentary exercise is to write,
meal = meal + meal * tax
You are correct in your assessment if this is where you are at on that step.
Assuming the tip is calculated as,
15 / 100
then the following would apply to the problem...
meal *= 1 + tip
which in the rudimentary code is,
meal = meal + meal * tip
Thanks for your prompt reply. I eventually discovered that your software was looking for meal = meal + meal*tax and not 'meal_tax = meal*(tax +1). I found this answer ambiguous and not intuitive because the value of meal (47.5) on one side of the equation is not equal to the value of meal on the other side (44.5)
What is wrong with differentiating between a meal with or without tax, e.g. with 'meal_tax' (with Tax) and 'meal' (without tax)?
Thanks for your help,
That is because the interpreter completes the right side before assigning the result to the left side. The left side variable is overwritten with that result. The value on the right side no longer exists at that point.
The interpreter always works with values as the data. Expressions as we see them are values to the interpreter. Evaluation always comes first.
Let's first consider that once we declare a variable, the memory it takes is lost if we never use the variable again. That is what makes expressions so invaluable... They remove the need for caching.
meal + meal * tax
is an expression, the value of which is computed and the only thing the interpreter sees at that point. The outcome overwrites the old value of meal once the assignment is complete.
The expected result and the intuitive result do often differ in courses with strict expectations. The instructions on this one must be followied.
meal *= (1 + tax + tip)
is not the levy to solve this particular exercise.
meal *= (1 + tax) * (1 + tip)
is what solves for the levy the SCT expects.
Thanks for your assistance Roy
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.