SRL Archive - General

Withdrawing Algorithm


Simtoon

2011-02-04 07:38:13

IM SO STUCK PLEASE HELP :D


I have to make a ATM System i have eveything worked out but i cant seem to get the withdrawing right..

I need something to be able to withdraw money out of an atm.. Withdrawing only 50 and 20 dollar notes..

It needs to work out how many 50 and 20 notes it needs give to the person..




Dim temp = TextBox1.Text
Dim a50 As Integer = 0
Dim a20 As Integer = 0




While temp >= 50
temp -= 50
a50 += 1
End While

While temp >= 20
temp -= 20
a20 += 1
End While

I did that in vb, which didnt work well


Can anyone help me, any language is fine

HyperSecret

2011-02-04 09:43:33


Dim temp = TextBox1.Text
Dim a50 As Integer = 0
Dim a20 As Integer = 0

a50 = temp / 50; //divide by 50 to figure out how many 50s

temp = temp - (50 * a50); //subtract the amount of 50s from the amount

a20 = temp / 20; //divide the current amount by 20 to figure out how many 20s

temp = temp - (20 * a20); //subtract the amount of 20s from the amount

//Then you need to check if temp is 0, to make sure they withdrew a valid amount

Hope this helped.

Simtoon

2011-02-04 10:25:43

I forgot to mention it needs to withdraw amounts like 210, 480 etc. And if its out of 50s, it uses 20s for like $100 etc ….

Thats why i got stuck.

HyperSecret

2011-02-04 12:51:02

Then just compare how many 50s you need to how many are available and if it's not possible don't change the temp value at all, then proceed to the 20s with the original amount.

Boreas

2011-02-04 13:00:39

Deal with one problem at a time
program new;
var Amount, n50, n20, Remainder, Stock50: integer;

begin

Amount := 220;
Stock50 := 0;

if (Amount mod 10) > 0 then
begin
writeln('Please enter a multiple of 10');
exit;
end;

N50 := Amount /50; //intial N50

if N50 > Stock50 then //check if ran out
N50 := Stock50; //fix N50

Remainder := Amount - N50*50; //intial remainder

if (Remainder mod 20) > 0 then //check if 20s will work
begin
Dec(N50);
Remainder := Amount - N50*50; //fix remainder
end;

N20 := Remainder/20; //get 20s

if (N50 < 0) or (N20 < 0) or (N50*50+N20*20<>Amount) then
begin
writeln('Please go see teller');
exit;
end;

writeln('N50 '+inttostr(N50)+' N20 '+inttostr(N20));

//DecEx(Account, Amount);
//DecEx(Stock50, N50);
//DecEx(Stock20, N20);
//EjectBills(N50, N20);
end.

Simtoon

2011-02-04 20:59:07

Thanks Boreas <3