Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Been gone so long...
Been gone so long...
2005-07-15, 6:12 AM #1
Hi!
Scuse me for being gone for so long, but I've been busy in Waisting time. I come with a COG problem...

The question is, why is my INT read as a FLEX?
Code:
int		rant				local
int		rantt				local

rant=(rand()*5);	rantt=(rant*2)+10;
SetTimerEx(GetSoundLen(ctempo),7,rantt,0);

printflex(GetParam(0));


Result on the print: A full decimal number. 13.364818 etc.

So, what's missing in the equation so I only get even numbers from 10 and up?

/Edward
Edward's Cognative Hazards
2005-07-15, 10:07 AM #2
Everything gets treated as a float...there's a couple ways to truncate it to an int though, such as:
a = a - a % 1;
Air Master 3D (my iPhone game)
My Programming Website
2005-07-16, 5:10 AM #3
Great! Thanks! I now get whole int numbers!

Now, I see there be a problem with my equation, or something else, for I'm also getting the odd numbers. How do I get only the even numbers (10, 12, 14, 16...)

/Edward

Nevermind... Figured it out... %2!
Edward's Cognative Hazards
2005-07-16, 5:30 AM #4
I'm not completely sure what you want to do, but if you are trying to round numbers to their next even neighbour, then you could truncate the number using Sige's code, and, if the new number is uneven (number % 2 = 1), simply add 1.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2005-07-16, 9:39 AM #5
To truncate to the nearest (but always less than or equal to) even value, you'd do just what edward said, a = a - a % 2;
To get odd numbers under the same condition you could do a = a - (a - 1) % 2; (I think, haven't tried that :P)
Air Master 3D (my iPhone game)
My Programming Website
2005-07-16, 11:39 AM #6
Actually, I think he could just move the truncate code. Try putting the truncation between rant=(rand()*5); and rantt=(rant*2)+10; statements.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come

↑ Up to the top!