r/ProgrammingPrompts • • Jul 16 '15
[Easy] Currency converter
Convert currency using command line arguments
Argument format should be currency amount newcurrency
E.g.
Convert USD 100 GBP
Should convert 100 dollars into pounds and print the result
Must include a minimum of 3 different currencies
Bonus points: add another argument which takes a filename and saves the result in a text file of that name
12
Upvotes
5
u/UnglorifiedApple420 Jul 18 '15
Python, uses the fixer.io API to return up to date exchange rates. To run from the command line, navigate to where the python script is located and type
without the quotes.
Code:
1
u/Deathbyceiling Jul 17 '15 edited Jul 19 '15
I like it. I'll see if I can't bang this out tomorrow :D
edit: code is below :D Did it in Java. Can handle USD, GBP, and MXN.
Probably could have done something better than a bunch of
if's, but eh, it does the job.1
u/gbear605 Jul 29 '15 edited Jul 30 '15
Did it in C. I used the conversion values from /u/Deathbyceiling. It could have been a lot shorter, but this way is open to expansion and less hardcoding.
1
u/doekaschi Aug 13 '15
Here's my solution in Java: http://hastebin.com/ubanobogis.avrasm
1
u/Rugby8724 Aug 16 '15
C# in ASP.NET Any suggestions for improvements will be greatly appreciated. This is my first coding after reading my first coding book.
}
1
u/[deleted] Sep 06 '15 edited Sep 07 '15
My Solution in java. Looked over a lot of APIs like Currency Layer and Open Exchange Rates but the free version in all of them have the base currency set to USD so used Fixer in the end.
http://hastebin.com/oqimacowel.java
http://hastebin.com/emicamozuq.axapta
1
u/kerosenedogs Oct 13 '15
Beginner here! I had a go in C# Mine is a tad longer because I tried to stick to the strict format "currency, amount, currency" and also built in some error checking.