-5
Guys I’m having trouble solving this problem, could someone help me? The problem of study is this:
In a small country on the planet Cyber, the current currency is B$. This currency has banknotes of B$50.00, B$10.00, B$5.00 and B$1.00. You have been hired to implement the ATM withdrawal system, and to do so you must always release as few notes as possible for a certain amount requested. Your algorithm will have the input value to be removed from the cash and will issue the total of each note needed to compose the requested value (so that this total is the minimum possible). (2,0 points). The algorithm must be closed when the value to be removed is 0(zero). Note: No serve may exceed B$1000 bits. Example: Value of Withdrawal: 650,00 Notes: 6 100,00 banknotes and a 50,00 banknote
And I did it:
int cedCinq = 50;
int numCedCinq;
int cedDez = 10;
int numCedDez;
int cedCinc = 5;
int numCedCin;
int cedUm = 1;
int numCedUm;`
double dinheiro = 1000;
double saque, resto;
Console.WriteLine("Digite o valor que deseja sacar: ");
saque = double.Parse(Console.ReadLine());
if (saque > dinheiro)
{
Console.WriteLine("Valor de limite excedido, não pode ser sacado esse valor!");
}
else if (saque == 0)
{
Console.WriteLine("Saque realizado!");
}
numCedCinq = Convert.ToInt32(saque / cedCinq);
resto = saque % cedCinq;
numCedDez = Convert.ToInt32(resto / cedDez);
resto = saque % cedDez;
numCedCin = Convert.ToInt32(resto / cedCinc);
resto = saque % numCedCin;
numCedUm = Convert.ToUInt16(resto / cedUm);
resto = saque % numCedUm;
Console.WriteLine("Do valor que foi solicitado " + saque + " foram usadas essas cédulas - Cinquenta: " + numCedCinq +
" Dez: " + numCedDez + " Cinco: " + numCedCin + " Um: " + numCedUm);
Console.ReadLine();`
How can I solve this in a much easier way?
You can use array for this. Know about?
– Kevin Kouketsu
What is your specific question? Take a look at [tour] and [Ask]. Did you read the answer I gave in your other question? https://answall.com/a/348159/101.
– Maniero
Yes Maniero, I saw your answer and I believe I thanked you about it. My question is whether there is a simpler way to solve this problem, because I am not able to deduce a different way and also my resolution is with a problem that I do not know how to solve.
– Igor Pompeo
@Igorpompeo you did not specify any problem in your thread. You had doubts about the implementation, whether there was an easier way.
– Kevin Kouketsu
Sorry guys I’m trying to resolve this as soon as I found out that I need to develop this for today and I was caught by surprise, it’s not merit but anyway... My biggest problem is the logic of taking the value to split it up and bring in the least amount of cedeulas for that amount.
– Igor Pompeo
If any answers are useful, either from your previous post or this one, mark it as a response.
– Kevin Kouketsu