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

Username:   Password: 
 RegisterRegister   
 using mod with real values
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Prince




PostPosted: Thu Mar 27, 2003 11:38 am   Post subject: using mod with real values

unless this just isnt possible, im getting an error saying that assigned value is the wrong type

code:

function modX (x, y : real) : int
    var imod : int
    imod := x mod y % error given for y
    result imod
end modX


is there any way to complete this without changing the variable type?
Sponsor
Sponsor
Sponsor
sponsor
Blade




PostPosted: Thu Mar 27, 2003 11:41 am   Post subject: (No subject)

you cant use real numbers in coordinates or sizes or anything like that, they have to be integers, because you cant use half of a pixel..
Tony




PostPosted: Thu Mar 27, 2003 12:11 pm   Post subject: (No subject)

well mod just tells you if it devides compleatly into the number.

so

code:

function modReal(num1:real, num2:real):real

if (num1/num2) = round(num1/num2) then
result 0
else
result (num1/num2) - floor(num1/num2)
end if

end modReal

put modReal(10.2, 2.5)


the result should be 0.08... code is theoretical as I dont have compiler nearby at the moment... I need someone to confirm that this works
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Blade




PostPosted: Thu Mar 27, 2003 12:22 pm   Post subject: (No subject)

ah, sorry man, i misunderstood the question.. but yea, tony, i tested it and it works
Prince




PostPosted: Thu Mar 27, 2003 5:10 pm   Post subject: (No subject)

thnx tony... it works btw but it still sends out decimal numbers (unless thats wat u wanted it to do) so im gonna try and fix that part
Tony




PostPosted: Thu Mar 27, 2003 6:26 pm   Post subject: (No subject)

mod gives you a remainder of the division.

modReal acts in the same way as mod, but since both numbers can be real now, so is the remainder.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: