Post Reply 
(11C) Currency Converter
10-01-2018, 06:00 AM (This post was last modified: 10-01-2018 07:39 AM by Gamo.)
Post: #1
(11C) Currency Converter
Program to convert "three" foreign exchange rates.


Procedure:

[A] Rates #1
[B] Base Rates
[C] Rates #2

Store rates #1 to R0
Store rates #2 to R1

n [A] display exchange rates to B based on A rates
n [C] display exchange rates to B based on C rates

n [B] display exchange rates of A based on B rates
-n [B] display exchange rates of C based on B rates

--------------------------------------------------------------------
Example: f [USER] f [FIX] 2

1 USD (United States) =
0.862441 EUR (Euro)
0.767699 GBP (British Pound)

.862441 [STO] 0 // Rate on LBL [A] (Euro)
.767699 [STO] 1 // Rate on LBL [C] (British Pound)

5 USD is how many Euro?
5 [A] display 4.31
Answer is 4.31 Euro

5 USD is how many GBP?
5 [C] display 3.84
Answer is 3.84 GBP

20 Euro is how many USD?
20 [B] display 23.19
Answer is 23.19 USD

20 GBP is how many USD?
20 [CHS] [B] display 26.05 USD // for GBP to USD use Negative Value

--------------------------------------------------------
Program: Exchange Rates
Code:

LBL A
RCL 0
x
RTN
LBL 0
1/x
GSB A
1/x
RTN
-------------------------------------------------------
LBL B
X>0
GTO 0
1/x
GSB C
1/x
CHS
RTN
-----------------------------------------------------
LBL C
RCL 1
x
RTN

Gamo
Find all posts by this user
Quote this message in a reply
10-01-2018, 11:58 AM (This post was last modified: 10-01-2018 11:59 AM by Dieter.)
Post: #2
RE: (11C) Currency Converter
(10-01-2018 06:00 AM)Gamo Wrote:  Program to convert "three" foreign exchange rates.

Gamo, I see you are using two techniques that have been used in earlier conversion programs:

1. Multiplying by a factor is done directly, while the inverse division is done by 1/x GSB A 1/x. This is a good idea if the conversion factor is hard-coded in the program so that it will occupy 8, 10 or more steps. This way the constant has to be coded only once. But here this does not apply: the factor is stored in a data register, so the 1/x GSB A 1/x method does not make much sense. A simple division (RCL 0 ÷) is shorter and runs much faster.

2. Using a sign for flagging input is a good idea to handle two different calculations, depending on whether the input is positive or negative. This makes sense if the user cannot directly access different parts of the program, for instance on the 12C: there are no labels, so the program is always started at the beginning with [R/S]. Here the sign of the input can make the program branch to different routines: positive? do this, negative? do that. But in our case the 11C offers five labels A...E that can be accessed directly. So the whole program can be coded much simpler:

Code:
LBL A  //convert to currency 1
RCL 0
x
RTN
LBL B  //convert from currency 1
RCL 0
÷
RTN
LBL C  //convert to currency 2
RCL 1
x
RTN
LBL D  //convert from currency 2
RCL 1
÷
RTN

After storing the constants you simply press [A] or [B] to convert to/from Euros and [C] or [D] to convert to/from Pounds:

  5 [A] =>   4,31
20 [B] => 23,19

  5 [C] =>   3,84
10 [D] => 13,03

This way the user does not have to care about the sign, he just presses a unique key for each conversion.

Another idea:
The 11C has five label keys A...E. These could be used for up to five currency conversions. This time a positive input may convert to a currency and a negtive input back from that currency:

5 [A] => -4,31
   [A] =>  5,00

How about that? Will you give it a try ?-)

Dieter
Find all posts by this user
Quote this message in a reply
10-01-2018, 12:49 PM
Post: #3
RE: (11C) Currency Converter
(10-01-2018 11:58 AM)Dieter Wrote:  positive input may convert to a currency and a negtive input back from that currency:

5 [A] => -4,31
   [A] =>  5,00

Nice idea to do both conversion with 1 key. The numbers "round-trip" too Smile

I suggest same currency (say, local currency) for negative, so conversion can be chained ...

5 [A] [B] => currency A to currency B
Find all posts by this user
Quote this message in a reply
10-01-2018, 01:00 PM (This post was last modified: 10-01-2018 01:37 PM by Gamo.)
Post: #4
RE: (11C) Currency Converter
This update now don't use the
Reverse Division and Sign Change as Flags.

So this one is the straight forward program now all conversions
is in there own labels.

LBL A convert USD --> Euro // 5 --> 4.31
LBL B convert USD --> GBP // 5 --> 3.84
LBL C convert Euro --> USD // 20 --> 23.19
LBL D convert GBP --> USD // 20 --> 26.05

Program: Currency Converter Updated II
Code:

LBL A
RCL 0
x
RTN
LBL 1
RCL 0
÷
RTN
------------------------------------------
LBL B
RCL 1
x
RTN
LBL 2
RCL 1
÷
RTN
-----------------------------------------
LBL C
GSB 1
RTN
----------------------------------------
LBL D
GSB 2
RTN

----------------------------------------

Updated III Use Signs as Flags with only two labels.
Code:

LBL A
X>0
GTO 1
RCL 0
÷
CHS
RTN
LBL 1
RCL 0
x
RTN
----------------------------------------
LBL B
X>0
GTO 2
RCL 1
÷
CHS
RTN
LBL 2
RCL 1
x
RTN

Example:

5 [A] ---> 4.31 // USD to Euro
20 [CHS] A ----> 23.19 // Euro to USD

5 [B] ---> 3.84 // USD to GBP
20 [CHS] [B] ---> 26.05 // GBP to USD

Remark:
Of all 3 versions the most user friendly
I believed is the Updated II
Personally I like Updated III

Gamo
Find all posts by this user
Quote this message in a reply
10-01-2018, 04:02 PM (This post was last modified: 10-01-2018 04:24 PM by Dieter.)
Post: #5
RE: (11C) Currency Converter
(10-01-2018 01:00 PM)Gamo Wrote:  Program: Currency Converter Updated II
Code:
LBL C
GSB 1
RTN
----------------------------------------
LBL D
GSB 2
RTN

Maybe I don't get the point and this is a very silly question, but...
...why don't you just replace LBL 1 with LBL C and LBL 2 with LBL D ?

(10-01-2018 01:00 PM)Gamo Wrote:  Updated III Use Signs as Flags with only two labels.

Great. That's an even better version that can be extended to five currencies.

Idea: what about another CHS after the multiplication? This way the output is flagged just as the input. So you know that positive input/output means USD and negative values are EUR or GBP.

(10-01-2018 01:00 PM)Gamo Wrote:  Remark:
Of all 3 versions the most user friendly
I believed is the Updated II
Personally I like Updated III

Then leave it the way it is. I'm glad you like it. ;-)

Finally, here is an "extended version" for five currencies that does the same thing via indirect addressing.
Store the conversion factors in R1, R2, R3, R4 and R5 respectively.

Code:
LBL A
1
GTO 0
LBL B
2
GTO 0
LBL C
3
GTO 0
LBL D
4
GTO 0
LBL E
5
LBL 0
STO I
R↓
x>0?
GTO 1
RCL (i)
÷
CHS
RTN
LBL 1
RCL (i)
x
CHS
RTN

Dieter
Find all posts by this user
Quote this message in a reply
10-01-2018, 04:37 PM
Post: #6
RE: (11C) Currency Converter
(10-01-2018 04:02 PM)Dieter Wrote:  Idea: what about another CHS after the multiplication? This way the output is flagged just as the input.
So you know that positive input/output means USD and negative values are EUR or GBP.

No need to add CHS. Instead, put the sign in conversion factor.

It will be more convenient with negative currency all refer to the same currency, say US.
This is especially nice for currency with close to one conversion rate, to tell them apart.

With this setup, A = currency A, B = currency B ...

currency A of 5 to currency B, just key: 5 [A] [B]
Find all posts by this user
Quote this message in a reply
10-01-2018, 06:05 PM (This post was last modified: 10-01-2018 06:06 PM by Dieter.)
Post: #7
RE: (11C) Currency Converter
(10-01-2018 04:37 PM)Albert Chan Wrote:  No need to add CHS. Instead, put the sign in conversion factor.

That's a good idea. This way you can even decide whether you want to apply the sign convention or not.

(10-01-2018 04:37 PM)Albert Chan Wrote:  It will be more convenient with negative currency all refer to the same currency, say US.
This is especially nice for currency with close to one conversion rate, to tell them apart.

With this setup, A = currency A, B = currency B ...

currency A of 5 to currency B, just key: 5 [A] [B]

I now have read these lines at least three times but I still don't know what exactly you want to say here. Sorry. ;-) But I have a first idea of what may be the idea here:

Remove the CHS commands from the program. Store the conversion factors as –USD/currency, i.e. the negative inverse of the present factor. For instance –1,1595 in R1 and –1,3026 in R2. Now key [A] means EUR and key [B] stands for GBP. Pressing these keys converts these currencies into USD. Successive conversions may convert from currency A to currency B.

What is the equivalent of 15 Euros in British Pounds?

15 [A] => -17,39   press the EUR key. The negative sign indicates that 15 EUR are 17,39 USD
     [B] =>  13,35   press the GBP key. This now shows that the same 15 EUR (or 17,39 USD) are 13,35 GBP

So this is quite intuitive. [A] means Euros and [B] means Pounds. To convert 100 GBP into EUR you'd type 100 [B] [A] to get 112,34 EUR as the result.

Please correct me if this is not what you meant to say.

Dieter
Find all posts by this user
Quote this message in a reply
10-01-2018, 06:28 PM (This post was last modified: 10-01-2018 06:35 PM by Albert Chan.)
Post: #8
RE: (11C) Currency Converter
(10-01-2018 06:05 PM)Dieter Wrote:  What is the equivalent of 15 Euros in British Pounds?

15 [A] => -17,39   press the EUR key. The negative sign indicates that 15 EUR are 17,39 USD
     [B] =>  13,35   press the GBP key. This now shows that the same 15 EUR (or 17,39 USD) are 13,35 GBP

So this is quite intuitive. [A] means Euros and [B] means Pounds. To convert 100 GBP into EUR you'd type 100 [B] [A] to get 112,34 EUR as the result.

This is exactly what I meant.
Negative numbers = US dollar, [A] = currency A, [B] = currency B ...
All currencies can now convert among themselves easily Smile
Find all posts by this user
Quote this message in a reply
10-02-2018, 01:53 AM
Post: #9
RE: (11C) Currency Converter
Dieter

Your "Extended Version" is very well done !!

Negative Value is the Local Value.
Positive Value are all other Five rates on labels A to E


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




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