|
|
Joined: Aug 2002
Posts: 1,521
Hard-core CEG\'er
|
OP
Hard-core CEG\'er
Joined: Aug 2002
Posts: 1,521 |
If I ask the user to enter a float number (units are feet), how can I manipulate the variables so that the output is an integer in feet and a float in inches? I tried to just cut off the decimals (to get my feet unit) by simply making the float "feet" equal to int "feet". But when I do that I get the error message: warning, assignment to 'int' from 'float'.
Chris G.
~ 98 Mystique LS ATX
|
|
|
|
|
Joined: Mar 2002
Posts: 1,573
Hard-core CEG'er
|
Hard-core CEG'er
Joined: Mar 2002
Posts: 1,573 |
someInt = int(someFloat)
or something like that? i think. if that doesnt work i can do a little more research for you
EDIT ohhh..... now i get what you are trying to do.
you need to use multiplication, mod, and division, as well as integer division. you want me to be a good teacher or just give you the answer? 
Last edited by Eli; 09/11/03 09:15 PM.
now officially a troll, i guess. used to have a black 96 SE, until it broke down one too many times.
now I'm hunting for a motorycle.
|
|
|
|
|
Joined: Jul 2000
Posts: 4,397
b0x @dm1n
|
b0x @dm1n
Joined: Jul 2000
Posts: 4,397 |
That's what I would do. I believe it's called type cast!
-Andy
Andy W.
The problem with America is stupidity.
I'm not saying there should be a capital punishment
for stupidity, but why don't we just take the safety
labels off of everything and let the problem solve itself?
|
|
|
|
|
Joined: Nov 2002
Posts: 55
CEG\'er
|
CEG\'er
Joined: Nov 2002
Posts: 55 |
i dont know if you have doing C++ programming long, but there are several websites out there that can help. my favorite is devshed.com
Green '99 Contour SE Sport ATX -- wrecked
Silver '00 CSVT 3L hybrid
Silver '95 Thunderbird "3.8 V6" -- swapped 5.0 from wrecked mustang FREEBIE!!!
|
|
|
|
|
Joined: Mar 2002
Posts: 1,573
Hard-core CEG'er
|
Hard-core CEG'er
Joined: Mar 2002
Posts: 1,573 |
here is what i would do. take the number that the user puts in 4.5 feet and multiply by 10. then do integer division on it, / 10 - and save the result - 4 as feet. then do % mod on it, which returns the remainder. 45 mod 10 = 5. divide that by 10, float style, to get .5 and then multiply by 12 - for inches. 6!
thats not the most efficient way to do it, but its good to know how to do that if you ever need to do funny things like that - ie seperate out input into 1000 100 10 and 1s places.
the most efficient way to do it is to multiply by 12 = 54. do integer division by 12, the answer is 4 (feet). then mod by 12 - 54 % 12 = 6 (inches).
either way should work, if i havent forgotten everything... and its probably best to understand how both ways work.
now officially a troll, i guess. used to have a black 96 SE, until it broke down one too many times.
now I'm hunting for a motorycle.
|
|
|
|
|
Joined: Oct 2002
Posts: 1,165
Hard-core CEG\'er
|
Hard-core CEG\'er
Joined: Oct 2002
Posts: 1,165 |
Just use a typeless language like perl and then not ever have to worry about that nonsense again.
$scalar power!
Cheers! ::dodges tomatoes::
Tim
'01 GTP: 3.3" pulley, Headers, 3" Exhaust, Straight Pipe, Intense Air to Water Intercooler. Pictures
Old Ride: 95 Mystique LS V6 ATX: Pictures
|
|
|
|
|
Joined: Mar 2002
Posts: 1,573
Hard-core CEG'er
|
Hard-core CEG'er
Joined: Mar 2002
Posts: 1,573 |
<------ is frightfully afraid if perl
now officially a troll, i guess. used to have a black 96 SE, until it broke down one too many times.
now I'm hunting for a motorycle.
|
|
|
|
|
Joined: Oct 2002
Posts: 1,165
Hard-core CEG\'er
|
Hard-core CEG\'er
Joined: Oct 2002
Posts: 1,165 |
What's so scarey abo... s/([a-zA-Z0-9].*?)/$1\sperl/isg; whoops... damn keyboard.
'01 GTP: 3.3" pulley, Headers, 3" Exhaust, Straight Pipe, Intense Air to Water Intercooler. Pictures
Old Ride: 95 Mystique LS V6 ATX: Pictures
|
|
|
|
|