Posts: 3
Threads: 1
Joined: May 2003
Im tryin to make a program that you input the price of an item and the amount of money the customer gives and have it output the amount of 10s,5s,1s,Quarters,Dimes,Nickles and pennies. How do I get it to sort them? Thank you
hristopher
Posts: 1,439
Threads: 15
Joined: Apr 2003
Do you mean you want to know the least amount of coins you can give as change? You could write a loop like this:
Code:
input "Enter money:", money
dollars = money \ 100
money = money mod 100
do while money > 5
if money mod 25 = 0 then
quarters = quarters + 1
money = money - 25
elseif money mod 10 = 0 then
dimes = dimes + 1
money = money - 10
elseif money mod 5 = 0 then
nickels = nickels + 1
money = money - 5
end if
loop
pennies = money
print "dollars:"; dollars
print "quarters: "; quarters
print "dimes:"; dimes
print "nickels:'; nickels
print "pennies:"; pennies
Not sure if that will work... just typed it off the top of my head. But the general logic should be right. That's probably the long way around... will post better method after I type it in and test it...
Posts: 1,439
Threads: 15
Joined: Apr 2003
Erm... better way - change the middle of the code to this:
Code:
dollars = money \ 100
money = money Mod 100
quarters = money \ 25
money = money Mod 25
dimes = money \ 10
money = money Mod 10
nickels = money \ 5
money = money Mod 5
pennies = money ' whatever's left
Hope this helps...
Posts: 3
Threads: 1
Joined: May 2003
like this...
Enter price of item. 24.35
Enter amount tendered. 30
0 tens
1 five
0 ones
2 Quarters
1 Dime
1 Nickle
0 penies
..........Thats what i need.
hristopher
Posts: 3
Threads: 1
Joined: May 2003
it keeps coming up that it cant devide by 0
hristopher
Posts: 1,439
Threads: 15
Joined: Apr 2003
Yes, that's what my code did.
here's a more complete example:
Code:
INPUT "Enter price of item:", price
INPUT "Enter amount tendered:", tender
money = tender - price
fives = money \ 500
money = money Mod 500
dollars = money \ 100
money = money Mod 100
quarters = money \ 25
money = money Mod 25
dimes = money \ 10
money = money Mod 10
nickels = money \ 5
money = money Mod 5
pennies = money ' whatever's left
you should be able to add tens, 20s etc...[/code]