Post Reply 
(12C) Tip Calculation
10-08-2017, 12:02 PM (This post was last modified: 04-19-2018 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:

STO 1 [Bill ] 
R/S
STO 2 [ %Tip ] 
R/S
STO 3 [ Split ] (if only yourself use 1)
R/S
RCL 1 [ Tip per Person ]
RCL 2
%
RCL 3
/
R/S
RCL 1 [Total per Person ]
RCL 2
%
+
RCL 3
/
GTO 00

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
Find all posts by this user
Quote this message in a reply
10-08-2017, 06:44 PM
Post: #2
RE: (10C) (12C) Tip Calculation
[quote='Gamo' pid='81142' dateline='1507464121']
Program:
Code:
ENTER [Bill ]
STO 1 
R/S
ENTER [ %Tip ] 
STO 2
R/S
ENTER [ Split ] (if only yourself use 1)
STO 3
R/S
...

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
Find all posts by this user
Quote this message in a reply
10-09-2017, 01:05 AM (This post was last modified: 10-09-2017 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
Find all posts by this user
Quote this message in a reply
04-19-2018, 01:12 PM (This post was last modified: 04-20-2018 10:51 AM by Gamo.)
Post: #4
RE: (10C) (12C) Tip Calculation
Tip Calculation program update.

Code:

STO 3
Rv
STO 2
Rv
STO 1
RCL 1
RCL 2
%
RCL 3
/
R/S
RCL 1
RCL 2
%
+
RCL 3
/
GTO 00

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
Find all posts by this user
Quote this message in a reply
04-20-2018, 07:28 AM (This post was last modified: 04-21-2018 09:00 AM by Dieter.)
Post: #5
RE: (12C) Tip Calculation
(04-19-2018 01:12 PM)Gamo Wrote:  How to input:
1. Bill Amount > ENTER
2. Tip Percent > ENTER
3. Person Count > n

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
02 R↓
03 /
04 R↓
05 R↓
06 R↓
07 %
08 +
09 LstX
10 GTO 00

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
Find all posts by this user
Quote this message in a reply
04-20-2018, 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
Find all posts by this user
Quote this message in a reply
04-21-2018, 08:53 AM (This post was last modified: 04-21-2018 09:28 AM by Dieter.)
Post: #7
RE: (12C) Tip Calculation
(04-20-2018 10:52 AM)Gamo Wrote:  Dieter Thank You
Now updated the instruction.
Your program is much better don't have to use any register.

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
Z   123,45    123,45    ?         15        ?         ?         15        ?
Y   15        3         123,45    ?         41,15     41,15     ?         47,32
X   3         15        3         41,15     15        6,17      47,32     6,17

    input     X<>Y      R↓        /         R↑        %         +         LastX

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
02 R↓
03 %
04 +
05 LastX

Stack diagram:

Code:
T   ?         ?         3         3         3         3 
Z   123,45    41,15     ?         ?         3         ?
Y   15        15        41,15     41,15     ?         47,32
X   3         3         15        6,17      47,32     6,17

    input     ST/ Z     R↓        %         +         LastX

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 




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