I am solving an exercise that I am having doubts, it is referring to a bank system, in which when presenting the value of draw, I must receive the smallest number of possible notes for the indicated value, I must also use the recursive method. Here's what I've done so far:
Question: Serving system - Earn R $ 80,00; - Cash returned 1 note R $ 50.00; - Cash returned 1 note R $ 20.00; - Cash return 1 note R $ 10.00.
As few notes as possible should be returned. Available notes: R $ 100,00, R $ 50,00, R $ 20,00, R $ 10,00 R $ 5,00 R $ 2,00. The rest (Value that can not be returned with available banknotes) should be printed if it exists.
The code:
var saque = 22;
var contador100 = 0;
var contador50 = 0;
var contador20 = 0;
var contador10 = 0;
var contador5 = 0;
var contador2 = 0;
if(saque != 0) {
if(saque >= 100) {
contador100++;
saque =- 100;
}
if(saque >= 50) {
contador50++;
saque =- 50;
}
if(saque >= 20) {
contador20++;
saque =- 20;
}
if(saque >= 10) {
contador10++;
saque =- 10;
}
if(saque >= 5) {
contador5++;
saque =- 5;
}
if(saque >= 2) {
contador2++;
saque =- 2;
}
}
console.log("A quantidade de notas 100 é: " + contador100);
console.log("A quantidade de notas 50 é: " + contador50);
console.log("A quantidade de notas 20 é: " + contador20);
console.log("A quantidade de notas 10 é: " + contador10);
console.log("A quantidade de notas 5 é: " + contador5);
console.log("A quantidade de notas 2 é: " + contador2);
But for some reason, this code considers only the first note, for example, in the draw of 22 reais, it will only present me a note of 20 and disregard the 2 reals.