I'm having trouble solving this problem, could anyone help me? The problem of study is this here:
In a small country on the planet Cyber, the current currency is the bit whose acronym is B $. In this currency there are bills of B $ 50.00, B $ 10.00, B $ 5.00 and B $ 1.00 bits. You have been hired to implement the withdrawal system at an ATM, and for this you should always release as few notes as possible for a certain amount requested. Your algorithm will have as input the value to be taken out of the box and you must issue the total of each note needed to compose the requested amount (so that this total is as little as possible). (2.0 points). The algorithm should be terminated when the value to be withdrawn is 0 (zero). Note: No draw can exceed B $ 1000.00 bits. Example: Amount of withdrawal: 650.00 Notes: 6 notes of 100.00 and a note of 50.00
And I did this:
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 a lot easier?