Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help with this div and mod stuff
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
foo fighter




PostPosted: 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. Very Happy

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
Sponsor
Sponsor
Sponsor
sponsor
Geminias




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: