4
I’m solving an exercise that I’m having doubts about, it refers to a bank system, in which when I present the withdrawal value, I should receive the least possible number of notes for the indicated value, I should also use the recursive method. Follow below what I’ve done so far:
Question: The Looting System - R$ 80,00 drawing; - Box returns 1 note R$ 50,00; - Box returns 1 note R$ 20,00; - Box returns 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 cannot be returned with available ballots) must 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 only considers the first note, for example, in the booty of 22 real, he will present me only a note of 20 and disregard the 2 real.
The question would be how to use the method recursively?
– mercador
It would be like making this issue of withdrawing with the lowest possible grades and implementing in the recursive method.
– Sabrina
@merchant I changed the code, but for some reason I still can’t make it work 100%.
– Sabrina
I used your code and fixed it so you’d understand the flaws in it and not harm your learning.
– user60252