Hi. I don’t understand why there is a number ‘1’ in the calculation to find the split in lesson 6’s challenge (1 + tax). Can anyone help explain this? Thank you so much.
/*Challenge:
4 people have dinner and want to split the bill.
Calculate the total with tax and then how much each person owes.
Assign it to the variable, ‘split’ and then print it out to the console area.
*/
let people:Double = 4
let subtotal:Double = 128
let tax = 0.13
var split:Double = 0
The tax rate is a decimal value so if you multiply the subtotal by just that value you end up with the proportion of the subtotal equating to how much tax is applied.
So 128 * 0.13 = 16.64.
If you add 1 to that tax value and then multiply the subtotal by that you get a result which equates to the subtotal plus the tax amount.
So 128 * 1.13 = 144.64.
If you then divide that result by the number of people (in this case 4) you get 36.16