(12C) Tip Calculation

10082017, 12:02 PM
(This post was last modified: 04192018 01:17 PM by Gamo.)
Post: #1




(12C) Tip Calculation
Here is the simple program to calculate Tip and Total per person.
This program work for HP calculator that doesn't have the LBL to assign to. Code:
How to input: 1. Enter bill amount then press R/S 2. Enter percent tip then press R/S 3. Enter how many person share then press R/S 4. R/S answer for Tip per Person 5. R/S answer for Total per Person Example: Bill Amount $123.45 %tip 15% with 3 persons 123.45 R/S > 15 R/S > 3 R/S > R/S result 6.17 tip > R/S result 47.32 Total 

10082017, 06:44 PM
Post: #2




RE: (10C) (12C) Tip Calculation
[quote='Gamo' pid='81142' dateline='1507464121']
Program: Code: ENTER [Bill ] Again, all ENTERs are obsolete and should be removed. BTW, for code like this you should use "code" tags, not "quote". This makes sure a fixed width font is used for better formatting. Dieter 

10092017, 01:05 AM
(This post was last modified: 10092017 01:45 AM by Gamo.)
Post: #3




RE: (10C) (12C) Tip Calculation
Dieter Thank You
I'm getting used to of the ENTER key. Make changed took off the ENTER Gamo 

04192018, 01:12 PM
(This post was last modified: 04202018 10:51 AM by Gamo.)
Post: #4




RE: (10C) (12C) Tip Calculation
Tip Calculation program update.
Code:
How to input: 1. Bill Amount > ENTER 2. Tip Percent > ENTER 3. Person Count 4. R/S answer for Tip per Person 5. R/S answer for Total per Person Example: Bill Amount $123.45 %tip 15% with 3 persons 123.45 ENTER 15 ENTER 3 > R/S result 6.17 Tip > R/S result 47.32 Total 

04202018, 07:28 AM
(This post was last modified: 04212018 09:00 AM by Dieter.)
Post: #5




RE: (12C) Tip Calculation
(04192018 01:12 PM)Gamo Wrote: How to input: So you enter the number of persons and then press the [n] key on the 12C? Or does this mean that the person count has to be > n ? What is n then? Yes, of course I think I know what you wanted to say, but that's not what you wrote. You can improve such posts if you follow some conventions that seem to work for most users here. For instance, if you want to refer to a key you may place its label in square brackets (such as [ENTER] or [R/S]). Arrows are fine if you want to show that a procedure is leading to the following result. For instance "amount [E] => tax". The instructions for your program would then look like this: bill amount [ENTER] tip percentage [ENTER] person count [R/S] => tip per person [R/S] => total amount per person Example: Bill Amount $123,45, tip is 15% with 3 persons 123,45 [ENTER] 15 [ENTER] 3 [R/S] => $6,17 tip per person [R/S] => $47,32 total per person Just take a little bit of care and everything will be as clear and unambiguous as possible. And here's another version that does not require any registers: Code: 01 X<>Y If your calculator has a R↑ key replace the three consecutive R↓ with one R↑. bill amount [ENTER] tip percentage [ENTER] person count [R/S] => tip per person [X<>Y] => total amount per person Dieter 

04202018, 10:52 AM
Post: #6




RE: (12C) Tip Calculation
Dieter Thank You
Now updated the instruction. Your program is much better don't have to use any register. Gamo 

04212018, 08:53 AM
(This post was last modified: 04212018 09:28 AM by Dieter.)
Post: #7




RE: (12C) Tip Calculation
(04202018 10:52 AM)Gamo Wrote: Dieter Thank You It's not magic, that's something you can do as well. There are essentially two things to consider: 1. Think about the problem you want to solve. Think hard. Don't take the first solution you find, there may be better ones. In this case you have written a program that does exactly what you would do if you had to calculate the tip manually: calculate the tip, add it to the bill amount and divide the result by the number of persons. Then calculate the tip again (although you have already done so before) and divide only the tip by the number of persons. Essentially you are doing the whole calculation twice. Does not sound like a good idea. But there is a better way: you can just as well first divide the bill by the number of persons and then (!) add the tip percentage. Instead of adding 15% to 123,45 and then divide this by 3 (while the "3" is required another time in the next step) you can simply divide 123,45 by 3 (=41,15) and then add 15% of that (=6,17). 2. Think about an effective implementation. If you first divide the bill amout by the number of persons, each of the three input data is only used once. If you have 41,15 in Y and 15 in X, the %function keeps the 41,15 in Y and returns 6,17 in X. So you only have to add both (=47,32). This again leaves 6,17 in LastX from where it can be recalled afterwards. This also means that you do not have to store the input in data registers. During the calculation each value is required only once, so you can be sure that it can all be done on the stack: Code: T ? ? 15 15 15 15 15 15 Since the 12C has no R↑ you just have to replace it with 3x R↓. The same idea – first divide the bill amount by the number of persons, then add the tip percentage – can be implemented even shorter on calculators with stack arithmetics, for instance the HP41: Code: 01 ST/ Z Stack diagram: Code: T ? ? 3 3 3 3 Dieter 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)