Currency converter
Description
Discuss (13 comments)
Many websites offer currency conversion. So for this puzzle, the objective is to convert one currency into another.
The input file is formatted as follows:
Important: The Dollar is considered the default currency and is always present.
Example:
It should contain p lines, one for each currency conversion query giving the amount in the target currency.
Important: The output result must be printed with exactly 4 fractional digit accuracy.
For the previous example, the solution is:
Input Specifications
Your program must take one and only one command line argument: the input file.The input file is formatted as follows:
- the first line contains the number n of foreign currencies
- the n following lines each contain a currency equivalence of the form
rate1 currency1 = rate2 currency2 - the next line contains the number p of conversions queries
- the p following lines each contain a currency conversion query of the form
amount source_currency => target_currency
Important: The Dollar is considered the default currency and is always present.
Example:
5 1 Euro = 1.4025 Dollar 2.5 Dollar = 70.5482 Ruble 0.1 Dollar = 4.448 Rupee 10 Pound = 15.909 Dollar 100 Dollar = 158.1 Real 4 10 Dollar => Euro 25 Euro => Real 100 Rupee => Ruble 5.50 Pound => Dollar
Output Specifications
You must print your output to the standard output (printf, etc...).It should contain p lines, one for each currency conversion query giving the amount in the target currency.
Important: The output result must be printed with exactly 4 fractional digit accuracy.
For the previous example, the solution is:
7.1301 55.4338 63.4426 8.7500
Scoring
The number of points is determined by the tests that are passed. You can see in the Unit Tests section for how many percent each test success contributes to the final score.Linked puzzles
This puzzle is part of a series, a more difficult version advancing the concepts required for this puzzle is: Money trail.© CoderCharts - All Rights Reserved
| Type | Puzzle | Pass | 204 | Fail | 84 | ||
| Scoring | Generic | Level | Novice | Points | 400 | ||
| Tags | arithmetic, conversion | ||||||
Unit Tests
| Name | CPU Unit | Memory Unit |
|---|---|---|
Small(15% of the score) 10 currencies, 100 conversions |
||
Medium(30% of the score) 50 currencies, 500 conversions |
||
Large(55% of the score) 100 currencies, 1000 conversions |
Confirm that you want to switch languages
Your current edits will be lost.
Confirm that you wish to load a previous submission
Your current edits will be lost.