Beta

Dude E Free

10 of 15jhancock

Description:

You work at a duty-free shop on the border of the United States and Canada.

Customers can pay you with either US or Canadian currency. You also offer to give them change in either currency.

Write a function which will return an array of strings representing the smallest possible combination of bills and coins to make change (from largest to smallest value)

The current exchange rates are as follows:

1 US dollar = 1.31 Canadian dollars
1 Canadian dollar = 0.76 US dollars
*** Note: when converting, always round down to the nearest cent

The available denominations are as follows:

United States
    Hundred Dollar Bill
  Fifty Dollar Bill
    Twenty Dollar Bill
    Ten Dollar Bill
    Five Dollar Bill
    One Dollar Bill
    Quarter
    Dime
    Nickel
    Penny

Canada
    Hundred Dollar Bill
    Fifty Dollar Bill
    Twenty Dollar Bill
    Ten Dollar Bill
    Five Dollar Bill
    Toonie
    Loonie
    Half Dollar
    Quarter
    Dime
    Nickel
  *** Toonie = $2, Loonie = $1
  

Because Canada has phased out the penny, when giving change in Canadian dollars, use the following rules for rounding to the nickel:

Round Down
  $1.01 or $1.02 -> $1.00
  $1.06 or $1.07 -> $1.05
Round Up
  $1.03 or $1.04 -> $1.05
  $1.08 or $1.09 -> $1.10
  

Note: you still accept Canadian pennies, but you don't give them as change.

The function should return null if any of the following conditions are met:

The amount paid is less than the price
The price or amount paid exceeds one million dollars
The price or amount paid is less than one cent
An invalid currency type is used as payment or requested as change

Example:

Customer buys $125.74 US dollars worth of merchandise.  
She gives you $200.00 (US dollars) and requests her change in Canadian dollars.
So, her change in US dollars would be $74.26
Converting that to Canadian dollars yields $97.28
Due to the phased out penny, her actual change is $97.30
That should be represented as follows:
  ["Fifty Dollar Bill", "Twenty Dollar Bill", "Twenty Dollar Bill", "Five Dollar Bill", "Toonie", "Quarter", "Nickel"]

Additional note: Javascript math makes me want to kill myself. I'm hoping that I handled all of my floating point arithmetic stuff correctly.

Fundamentals

Similar Kata:

Stats:

CreatedAug 31, 2016
PublishedAug 31, 2016
Warriors Trained207
Total Skips74
Total Code Submissions255
Total Times Completed15
C# Completions6
JavaScript Completions10
Total Stars4
% of votes with a positive feedback rating78% of 9
Total "Very Satisfied" Votes7
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes2
Total Rank Assessments7
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • jhancock Avatar
  • hobovsky Avatar
Ad