Function Coding Issues in RobotC

My team recently added a member who is a lot better than any of us at coding, and he is having some issues getting it to work. I am attaching the code; if you have any suggestions, let me know. You can’t attach a RobotC file, so it’s in a word document. We tried to switch our motors from 100 RPM to 160 RPM, and we were having trouble getting the encoders to work properly. He would have to input wild values into the function to get the motors to go the correct distance. We should only have to put in the distance in centimeters for it to run the distance (+/- 3cm) and that was far from the case. He did change the necessary values so they should work properly.
Code 12-13-16.docx (16.2 KB)

Could it be the unnecessary exclamation points located here instead of the other equal sign?
//Wait for Release------------------------------------------------
void waitForRelease()
{
while(nLCDButtons != 0){}
wait1Msec(5);
}

int count = 0;

void pre_auton(
)
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
bStopTasksBetweenModes = true;

//Declare count variable to keep track of our choice

//------------- Beginning of User Interface Code ---------------
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
//Loop while center button is not pressed
while(nLCDButtons***!***= centerButton)
{

Liam, those exclamation points help create a “not equal” sign. For example, 2 == 2 is true, as two is equal to two. 2 != 3 is also true, as two is not equal to three. This piece of code: while(nLCDButtons != 0) will loop inside the while loop until nLCDButtons does not equal zero, in other words meaning once no LCD buttons are pressed.

The issue SquirrelsRule is having is in the functions waitForPress() and waitForRelease. Here’s waitForPress:


void waitForPress()
{
    while(nLCDButtons == 0){}
    wait1Msec(5);
}

The while loop will run through the functions inside the curly brackets while nLCDButtons is zero. The wait1Msec call needs to be inside those curly brackets. Right now the while loop loops nothing, and without the delay the cortex doesn’t have time to update nLCDButtons.
How it should look:


void waitForPress()
{
    while(nLCDButtons == 0){
        wait1Msec(5);
    }
}

waitForRelease has the same issue, just move the delay inside the while’s curly brackets.

Thanks! I should have been more specific with the actual problem. We tried to switch our motors from 100 RPM to 160 RPM, and we were having trouble getting the encoders to work properly. He would have to input wild values into the function to get the motors to go the correct distance. We should only have to put in the distance in centimeters for it to run the distance (+/- 3cm) and that was far from the case.