Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   quick c question (http://www.chiefdelphi.com/forums/showthread.php?t=35149)

shobuda999 21-02-2005 15:45

quick c question
 
is it possible to do something like
variable1 = variable2;
if both variables are ints? for some reason, we're not able to do this and I'm pretty sure its allowed.

thanks,

Dan

Jon236 21-02-2005 15:52

Re: quick c question
 
Quote:

Originally Posted by shobuda999
is it possible to do something like
variable1 = variable2;
if both variables are ints? for some reason, we're not able to do this and I'm pretty sure its allowed.

thanks,

Dan


What happens?

nehalita 21-02-2005 15:53

Re: quick c question
 
it should be fine. what is the code exactly?

shobuda999 21-02-2005 15:54

Re: quick c question
 
Quote:

Originally Posted by Jon236
What happens?

I get a syntax error on the line below, but when I comment out the var1 = var2;
line above it compiles fine

shobuda999 21-02-2005 16:17

Re: quick c question
 
[above]
int counter = 0;
int tracker = 0;
counter ++
[below]

if (counter<60)
{
arm = 0;
}
tracker = counter;
else if (counter<tracker+32)
{
arm = 127;
l_motor=r_motor=191;
}
tracker = counter;
else if(counter < tracker + 55)
{
l_motor=r_motor=127;
arm = 255;
}

this is for dead reckoning without any kind of sensor using a clock of sorts.
i know this seems kind of strange, the reason I'm doing it this way is so I can easily make slight changes without having to change every value

thanks,
Dan

AIBob 21-02-2005 16:32

Re: quick c question
 
Code:

if (counter<60)
{
arm = 0;
}
tracker = counter;
else if (counter<tracker+32)
{
arm = 127;
l_motor=r_motor=191;
}
tracker = counter;
else if(counter < tracker + 55)
{
l_motor=r_motor=127;
arm = 255;
}

You have it being set between the else ifs.
there is not if that the else is attached to.
This is what is giving you the error, not the variable setting itself, just the placement of the setting.

Also note: you are setting tracker to counter before you check if it less than counter.

shobuda999 22-02-2005 13:51

Re: quick c question
 
:P thanks, I don't know what I was thinking. I was trying to get an autonomous mode done an hour before ship


All times are GMT -5. The time now is 04:37.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi