I've been grappling with this algorithm for the past few days, but unfortunately I haven't been able to come up with a successful solution yet. The available solutions seem to be too advanced for my current level of understanding. This problem must be solved using conditionals only; recursion and dynamic programming are not allowed.
The challenge is to determine the minimum number of coins needed to make change using the following denominations: 1, 0.5, 0.2, 0.1, 0.05, 0.02, and 0.01.
Here is the input required:
- Price of an item
- Total amount paid by the customer
My initial thoughts are as follows:
let price = +gets();
let paidSum = +gets();
// 'gets' is used to receive numerical input
let change = paidSum - price;
I was thinking that I could use Math.floor to extract the integer part and subtract it from the total change, but I'm unsure how to proceed with the remaining sum.
Would using modulo help me determine if the remaining sum includes any of the remaining change values, allowing me to subtract sequentially until reaching zero?
I understand that my question might not be perfectly articulated, but I really am stuck on this problem. I've managed to tackle every other task except this one. Thank you for your help.