Coding Help

Hey guys,
I’ve been trying to learn RobotC recently and I ran into this error with this function

void moveforward(int target, int wait)
{
  while((SensorValue[chassLe] + SensorValue[chassRe])/2) < target
  {
    motor[chassL] = 127;
    motor[chassR] = 127;
    wait1Msec(500);
    motor[chassL] = -25;
    motor[chassR] = -25;
  }
}

After compiling it gave me an error saying “Unexpected ‘<’ during parsing”, any help would be appreciated thanks in advance.

Your parentheses don’t go around what they should. < target is outside of them. Move the closing ) from after the 2 until after target.

Separately:

  1. 500 ms is 0.5 s. That’s a long time to wait before checking again.

  2. I’m assuming the last bit (-25s) is braking. Why would you keep braking before you get to your target? I think you want this outside and immediately following the while loop.

  3. The function is going to end right after setting the braking. You might want to put a short delay in after those.

  4. You’re passing your function a int called “wait,” but you’re not using it.

Thanks for the help!