# Cash Register not returning precise number

Tell us what’s happening:
This function doesn’t return the precise number of pennies. It should return 0.04, but it returns 0.03. The problem is in the while loop. It doesnt do the last iteration even though every condition is true. It literally makes no sense. Please help if you can make sense out of this code. Im very close to smashing my PC. thanks

``````
function checkCashRegister(price, cash, cid) {
const values = {
"PENNY": 0.01,
"NICKEL": 0.05,
"DIME": 0.1,
"QUARTER": 0.25,
"ONE": 1,
"FIVE": 5,
"TEN": 10,
"TWENTY": 20,
"ONE HUNDRED": 100,
}

let change = [];
let totalSum = 0;
let returnVal = cash - price;
let toReturn = returnVal;
let reversedArr = cid.reverse();

for (let i = 0; i < reversedArr.length; i++) {
if (values[reversedArr[i][0]] <= toReturn && reversedArr[i][1] > 0) {
console.log("working with:", reversedArr[i]);
let current = 0;
while (totalSum < returnVal && reversedArr[i][1] > 0 &&
totalSum + values[reversedArr[i][0]] <= returnVal) {
totalSum += values[reversedArr[i][0]];
current += values[reversedArr[i][0]];
toReturn -= values[reversedArr[i][0]];
reversedArr[i][1] -= values[reversedArr[i][0]];
console.log(totalSum);
console.log(toReturn);
console.log(reversedArr[i][1]);
}

if (current) {
change.push([reversedArr[i][0], current]);
}
}
}

return change;

}

console.log(checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05],
["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90],
["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]));

``````

User Agent is: `Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36`.