mercredi 2 janvier 2019

How to calculate change in JS

I have task in my academy "Write a program that determines the least amount of coins needed for a cashier to return change."

For example, if the price of something is 0.76 dollars and the customer has paid 1 dollar, the least amount of coins is 1 x 20 cents and 2 x 2 cents.

Use coins of one dollar, 50, 20, 10, 5, 2 and 1 cents.

On the first line, you will receive the price in dollars.

On the second line, you will receive how much the customer has paid in dolars.

Input:

0.76

1

Output: Print each required denomination on a new line, ordered from highest to lowest.

1 x 20 cents

2 x 2 cents

In this case I don't even know how to start my code. I'm stuck at the beginning.

Aucun commentaire:

Enregistrer un commentaire