This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Geoff Dittberner
about 9 years

why do I type meal twice?

Total is calculated by coding:

total = meal + meal * tip

why is it not just:

total = meal * tip

it seems like two meals is redundant?

Answer 54ccf36951b887dd82001272

1 vote

Permalink

The reason for this …

total = meal + meal * tip

… is that to get the total cost, we need to take the entire meal cost so far (prior to the tip), which is meal, and then add to that an additional percentage of the meal cost, based on the tip rate. So the actual tip that is paid is meal * tip. Adding the whole pre-tip meal cost to the actual tip, then becomes meal + meal * tip.

points
Submitted by Glenn Richard
about 9 years

1 comments

Geoff Dittberner about 9 years

tx!

Answer 54ccd65986f552898a0010ec

0 votes

Permalink

I think the main reason they have the calculation in that manner is more for the display of calculation ability of the script, don’t let that bother you now. your going to have fun later nutting out some of the stuff that comes up

enjoy :)

hope this helps?

points
Submitted by HMWT
about 9 years

1 comments

Geoff Dittberner about 9 years

tx!