GPWiki.org
GPWiki.org
It is currently Wed Jun 19, 2013 11:41 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Dec 28, 2009 11:23 pm 
Level 1 Cleric

Joined: Tue Jul 07, 2009 8:17 pm
Posts: 12
The debugger pipes up with an error on this line of code:

Code:
Quarters := Change div 0.25;


It gives the error message: "Operator not applicable to this operand type." This confuses me. Change is a real number, and Quarters is an integer. I would expect the div operator to return an integer to me, which is exactly what the variable Quarters is looking for. What am I missing here? Thanks.

--Gadfly


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 28, 2009 11:41 pm 
Gold Star Poster!

Joined: Sat Feb 04, 2006 8:09 pm
Posts: 104
Location: Virginia Beach
In c++, math operators, if you use math on a double and an int, it always returns a double.
It kind of makes sense really, But in C++ that would only throw a warning I belive, because 4/.25 is 16.00, which easily becomes an int.

But that's C++, I don't know the slightest about Pascal. but I suspect it might be the same.

Wouldn't it be easier to use modulus(remainder) division to find the change?
Either way, why not just try dividing quarters by an int, or making quarters a double and see if that's what's causing the problem?

_________________
Guess what?
HA HA!
Made you guess!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 29, 2009 8:31 pm 
Level 1 Cleric

Joined: Tue Jul 07, 2009 8:17 pm
Posts: 12
I was able to resolve the problem by using something similar to your second suggested method. I suppose pascal doesn't like the way I wanted to do things, even though it should've worked out just fine. Freakin' Pascal. I need to learn a different language.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 29, 2009 8:37 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2217
Location: England
The problem is that "x div y" is doing integer division, not floating point division.

0.25 is simply being rounded down to integer 0, an invalid denominator, so yielding an error. :)

It's the same as in your PI calculating routine we did back in the summer.

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 29, 2009 10:42 pm 
Gold Star Poster!

Joined: Sat Feb 04, 2006 8:09 pm
Posts: 104
Location: Virginia Beach
Glad I could help.

_________________
Guess what?
HA HA!
Made you guess!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group