Subject:
|
mixing variable types in IC
|
Newsgroups:
|
lugnet.robotics.handyboard
|
Date:
|
Sun, 14 Nov 1999 17:23:20 GMT
|
Original-From:
|
Ben Davis <bendavis@MIT.EDU&nomorespam&>
|
Viewed:
|
825 times
|
| |
| |
Hi John-
You can convert quantities from one data type to another
(it's called "casting", I believe).
The following computes the quantity x/y, then converts it
to a float:
-------------------------
int x, y;
float c;
float divide ( int x, int y)
{
c = (float) (x/y);
return c;
}
---------------------------
cheers,
--ben
>
> Now that I got past my nested function problem I have discovered that
> IC does not like mixing variable types. For instance, this results in
> an error:
>
>
> int x, y;
> float c;
>
> float divide ( int x, int y)
> {
> c = (x/y);
> return c;
> }
>
|
|
Message has 1 Reply: | | Re: mixing variable types in IC
|
| [Ben Davis] spake unto the ether: (...) Hmm, I think you want c = ((float)(x))/((float)(y)); Otherwise, the division will be done first as integers, giving an integer quotient, which you're then turning into a float. *Rich* (25 years ago, 14-Nov-99, to lugnet.robotics.handyboard)
|
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|