Need help with this div and mod stuff
Author |
Message |
foo fighter
|
Posted: Tue Dec 13, 2005 5:40 pm Post subject: Need help with this div and mod stuff |
|
|
Alright well this program is supposed to tell you how many bills and coins you need to make a dollar amount given by the user. Although, it only works with simple inputs like $150 and $200 and it doesn't work for something like $167.89
Could someone fix it for me.
code: |
var dollar_value : real
var num100, num50, num20, num10, num5, num2, num1 : real
var num025, num010, num005, num001 : real
color (green)
put "Enter a dollar amount : $" ..
color (blue)
get dollar_value
num100 := dollar_value div 100
num50 := dollar_value rem 50 div 50
num20 := dollar_value rem 50 div 20
num10 := dollar_value rem 20 div 10
num5 := dollar_value rem 10 div 5
num2 := dollar_value rem 5 div 2
num1 := dollar_value rem 2 div 1
num025 := dollar_value rem 1 div 0.25
num010 := dollar_value rem 0.50 div 0.10
num005 := dollar_value rem 0.25 div 0.05
num001 := dollar_value rem 0.10 div 0.01
put num100
put num50
put num20
put num10
put num5
put num2
put num1
put num025
put num010
put num005
put num001
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Geminias
|
Posted: Tue Dec 13, 2005 9:26 pm Post subject: (No subject) |
|
|
that's because the 'div' keyword takes whatever numbers you give it, real , integer, whatever, and it casts them into ints. so just use the '/' operation in your expression. |
|
|
|
|
![](images/spacer.gif) |
|
|