Hi. I have just a focusing question ( the programming language does not
make a difference ) which is related to the algorithm; does following
function type module have one or two an input parameter? I think that
if a dollar is one and if the euro is one, then there will be two input
parameters. Right? It is intended to feed the euro number and the programme
returns it in dollars.
module ( euro ) returns USD
return 1,4*euro
endmodule
Question about module
Started by jamesw, Oct 15 2008 04:58 AM
7 replies to this topic
#1
Posted 15 October 2008 - 04:58 AM
|
|
|
#2
Posted 15 October 2008 - 06:51 AM
For a simple currency converter that only goes in one direction, it will take one parameter. For something more advanced, you would need three parameters: the input value, the input currency, and the output currency.
#3
Posted 16 October 2008 - 03:05 AM
Great. And if I want to do a module which has two input parameters: euro-denominated sum and currency code. The value of the currency code is USD. The function refunds the euro-denominated sum received by it as a currency which is in accordance with the currency code. I think it would be like this; ?
module ( euro,USD ) returns USD ( in this; input parameters are euro and USD, right? )
return 1,4*euro
endmodule
OR:
MODULE eUSD( e, USD ) returns usd
IF e THEN RETURN 1,4*e
ENDIF
ELSE
IF USD THEN RETURN 0.7*USD
ENDIF
ENDMODULE
But, if this is better, "returns usd" or "returns usd or e"
module ( euro,USD ) returns USD ( in this; input parameters are euro and USD, right? )
return 1,4*euro
endmodule
OR:
MODULE eUSD( e, USD ) returns usd
IF e THEN RETURN 1,4*e
ENDIF
ELSE
IF USD THEN RETURN 0.7*USD
ENDIF
ENDMODULE
But, if this is better, "returns usd" or "returns usd or e"
#4
Posted 16 October 2008 - 07:37 AM
That should work (syntax being correct for the language, of course).
#5
Posted 17 October 2008 - 01:19 AM
Thank you. But do you mean that this ( and not the first, shorter version )should work? I think this is better, but tell me. And which is better, "returns usd" or "returns usd or e" OR: should I put "returns usd" and in another line "returns e" ? -I'm not sure. This is very close, I know.
MODULE eUSD( e, USD ) returns usd
IF e THEN RETURN 1,4*e
ENDIF
ELSE
IF USD THEN RETURN 0.7*USD
ENDIF
ENDMODULE
( p.s. you can answer also privately, but this forum is better )
MODULE eUSD( e, USD ) returns usd
IF e THEN RETURN 1,4*e
ENDIF
ELSE
IF USD THEN RETURN 0.7*USD
ENDIF
ENDMODULE
( p.s. you can answer also privately, but this forum is better )
#6
Posted 17 October 2008 - 07:42 AM
In the end, it comes down to a design decision. It should really meet 2 criteria:
1) it should work as written
2) it should be easy to extend in the future, if that extension is at all likely.
What you have just posted certainly meets condition 1, but it seems likely that at some point you'll want to be able to add Yen, Canadian Dollars, etc to your calculator. Can you see why your current solution(s) fail criteria 2?
1) it should work as written
2) it should be easy to extend in the future, if that extension is at all likely.
What you have just posted certainly meets condition 1, but it seems likely that at some point you'll want to be able to add Yen, Canadian Dollars, etc to your calculator. Can you see why your current solution(s) fail criteria 2?
#7
Posted 17 October 2008 - 11:41 AM
Thank you again. Well, Ihave decided that these two currencies are enough. If I want to add currencies, I will do a new module. So if this works; I think this is quite good, I made it myself. But I want to make sure; can you tell me;
MODULE eUSD( e, USD ) returns usd ( should this be usd, e ) ?? or is just usd ok?
IF e THEN RETURN 1,4*e
ENDIF
ELSE
IF USD THEN RETURN 0.7*USD
ENDIF
ENDMODULE
MODULE eUSD( e, USD ) returns usd ( should this be usd, e ) ?? or is just usd ok?
IF e THEN RETURN 1,4*e
ENDIF
ELSE
IF USD THEN RETURN 0.7*USD
ENDIF
ENDMODULE
#8
Posted 17 October 2008 - 01:14 PM
The e gives you the option of 2 directions, which I think is useful.


Sign In
Create Account


Back to top









