Jump to content

Question about module

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
jamesw

jamesw

    Newbie

  • Members
  • PipPip
  • 12 posts
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

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
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.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
jamesw

jamesw

    Newbie

  • Members
  • PipPip
  • 12 posts
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"

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
That should work (syntax being correct for the language, of course).
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
jamesw

jamesw

    Newbie

  • Members
  • PipPip
  • 12 posts
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 )

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
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?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
jamesw

jamesw

    Newbie

  • Members
  • PipPip
  • 12 posts
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

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
The e gives you the option of 2 directions, which I think is useful.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog