Please Help with RobotC!!

I keep getting the error “Executable statements not valid in ‘main’ declaration block.”
I am coding in the Pre Auton section.
Here’s my code.
PLEASE HELP SOON! Thanks!

#pragma config(UserModel, “E:/Robotics/2831 C SFMS 2016-2017/Main Program Robot C/Program/Motor And Sensor Setup/setup.h”)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include “Vex_Competition_Includes.c” //Main competition background code…do not modify!

int btnPressed1;
int btnPressed2;
int btnPressed3;
int red;
int left;
int lift;
int redleftlift;
int bluerightnolift;

/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////

void pre_auton()
{

bStopTasksBetweenModes = true;

bLCDBacklight = 1;
clearLCDLine(0);
clearLCDLine(1);
displayLCDCenteredString(0, "Red or Blue?");
btnPressed1 = nLCDButtons;
if( btnPressed1 == 1)
{
	red = 1;
	displayLCDCenteredString(0, "Red? Ok...");
	displayLCDCenteredString(1, "Left or Right?");
	btnPressed2 = nLCDButtons;
	if (btnPressed2 == 1)
	{
		left = 1;
		displayLCDCenteredString(0, "Left? Ok...");
		displayLCDCenteredString(1, "Yes Lift. No Lift");
		btnPressed3 = nLCDButtons;
		if (btnPressed3 == 1)
		{
			lift = 1;
			displayLCDCenteredString(0,"Red, Left, Lift");
			if( red == 1 && left == 1 && lift == 1)
				redleftlift = 1;
			bluerightnolift = 0;
		}
	}
}

}
if (btnPressed1 == 4)
{
red = 0;
displayLCDCenteredString(0,“Blue? Ok…”);
displayLCDCenteredString(1,“Left or Right?”);
btnPressed2 = nLCDButtons;

if (btnPressed2 == 4)
{
	left = 0;
	displayLCDCenteredString(0,"Right? Ok...");
	displayLCDCenteredString(1,"Yes Lift. No Lift");
	btnPressed3 = nLCDButtons;

	if (btnPressed3 = 4)
	{
		lift = 0;
		displayLCDCenteredString(0,"No Lift? Ok...");
		displayLCDCenteredString(1,"Blue, Right, No Lift");

		if (red == 0 && left == 0 && lift == 0)
		{
			bluerightnolift = 1;
			redleftlift = 0;
		}
	}
}

}

Well before we get to that I just wanted to say that the code you’re using won’t work for what you’re trying to achieve.

Next time, try to indent properly, like this:

void pre_auton() {

bStopTasksBetweenModes = true;

bLCDBacklight = 1;
clearLCDLine(0);
clearLCDLine(1);
displayLCDCenteredString(0, "Red or Blue?");
btnPressed1 = nLCDButtons;
if( btnPressed1 == 1) {
	red = 1;
	displayLCDCenteredString(0, "Red? Ok...");
	displayLCDCenteredString(1, "Left or Right?");
	btnPressed2 = nLCDButtons;
	if (btnPressed2 == 1) {
		left = 1;
		displayLCDCenteredString(0, "Left? Ok...");
		displayLCDCenteredString(1, "Yes Lift. No Lift");
		btnPressed3 = nLCDButtons;
		if (btnPressed3 == 1) {
			lift = 1;
			displayLCDCenteredString(0,"Red, Left, Lift");
			if( red == 1 && left == 1 && lift == 1) {
			redleftlift = 1;
			bluerightnolift = 0;
			}
		}
	}
}
if (btnPressed1 == 4) {
	red = 0;
	displayLCDCenteredString(0,"Blue? Ok...");
	displayLCDCenteredString(1,"Left or Right?");
	btnPressed2 = nLCDButtons;
	if (btnPressed2 == 4) {
		left = 0;
		displayLCDCenteredString(0,"Right? Ok...");
		displayLCDCenteredString(1,"Yes Lift. No Lift");
		btnPressed3 = nLCDButtons;
		if (btnPressed3 = 4) {
			lift = 0;
			displayLCDCenteredString(0,"No Lift? Ok...");
			displayLCDCenteredString(1,"Blue, Right, No Lift");
			if (red == 0 && left == 0 && lift == 0) {
				bluerightnolift = 1;
				redleftlift = 0;
			}
		}
	}
}
}

Ok thank you guys. I haven’t coded in vex but have a little out of it. I don’t even know what i was thinking with the if loop brackets. lol

USE THE CODE BLOCK FEATURE ON THIS FORUM SO WE GET THE SYNTAX HIGHLIGHTING WE SPENT YEARS BEGGING FOR!!!..

void pre_auton() {

bStopTasksBetweenModes = true;

bLCDBacklight = 1;
clearLCDLine(0);
clearLCDLine(1);
displayLCDCenteredString(0, "Red or Blue?");
btnPressed1 = nLCDButtons;
if( btnPressed1 == 1) {
	red = 1;
	displayLCDCenteredString(0, "Red? Ok...");
	displayLCDCenteredString(1, "Left or Right?");
	btnPressed2 = nLCDButtons;
	if (btnPressed2 == 1) {
		left = 1;
		displayLCDCenteredString(0, "Left? Ok...");
		displayLCDCenteredString(1, "Yes Lift. No Lift");
		btnPressed3 = nLCDButtons;
		if (btnPressed3 == 1) {
			lift = 1;
			displayLCDCenteredString(0,"Red, Left, Lift");
			if( red == 1 && left == 1 && lift == 1) {
			redleftlift = 1;
			bluerightnolift = 0;
			}
		}
	}
}
if (btnPressed1 == 4) {
	red = 0;
	displayLCDCenteredString(0,"Blue? Ok...");
	displayLCDCenteredString(1,"Left or Right?");
	btnPressed2 = nLCDButtons;
	if (btnPressed2 == 4) {
		left = 0;
		displayLCDCenteredString(0,"Right? Ok...");
		displayLCDCenteredString(1,"Yes Lift. No Lift");
		btnPressed3 = nLCDButtons;
		if (btnPressed3 = 4) {
			lift = 0;
			displayLCDCenteredString(0,"No Lift? Ok...");
			displayLCDCenteredString(1,"Blue, Right, No Lift");
			if (red == 0 && left == 0 && lift == 0) {
				bluerightnolift = 1;
				redleftlift = 0;
			}
		}
	}
}
}

how 2 do that?

See the attachment.

Where is your autonomous and driver control blocks?
Capture.PNG

what. :confused: that what I thought I did

test
void

yup, its in BB code in my original post

i think its broken

Why are the ints after the include function? Try moving them under the void brackets.

They’re global variables. It’d actually be best to put global variables right after the pragma and include statements, because those variables need to be ahead of any function referencing them, otherwise you get an error. Put them there like I said, and you won’t have that problem at all. Plus, if they’re a related set of variables that together are used to configure the robot, it’d be handy to put them all in one place so that you can make changes to settings more easily.

Properly indenting your code is very important. It not only makes it easier to read, it can make it easier to debug errors such as these. Here is your code as-is with proper indentation:

#pragma config(UserModel, "E:/Robotics/2831 C SFMS 2016-2017/Main Program Robot C/Program/Motor And Sensor Setup/setup.h")
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c" //Main competition background code...do  not modify!

int btnPressed1;
int btnPressed2;
int btnPressed3;
int red;
int left;
int lift;
int redleftlift;
int bluerightnolift;

/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////

void pre_auton()
{

	bStopTasksBetweenModes = true;

	bLCDBacklight = 1;
	clearLCDLine(0);
	clearLCDLine(1);
	displayLCDCenteredString(0, "Red or Blue?");
	btnPressed1 = nLCDButtons;
	if( btnPressed1 == 1)
	{
		red = 1;
		displayLCDCenteredString(0, "Red? Ok...");
		displayLCDCenteredString(1, "Left or Right?");
		btnPressed2 = nLCDButtons;
		if (btnPressed2 == 1)
		{
			left = 1;
			displayLCDCenteredString(0, "Left? Ok...");
			displayLCDCenteredString(1, "Yes Lift. No Lift");
			btnPressed3 = nLCDButtons;
			if (btnPressed3 == 1)
			{
				lift = 1;
				displayLCDCenteredString(0,"Red, Left, Lift");
				if( red == 1 && left == 1 && lift == 1)
					redleftlift = 1;
				bluerightnolift = 0;
			}
		}
	}
}
if (btnPressed1 == 4)
{
	red = 0;
	displayLCDCenteredString(0,"Blue? Ok...");
	displayLCDCenteredString(1,"Left or Right?");
	btnPressed2 = nLCDButtons;

	if (btnPressed2 == 4)
	{
		left = 0;
		displayLCDCenteredString(0,"Right? Ok...");
		displayLCDCenteredString(1,"Yes Lift. No Lift");
		btnPressed3 = nLCDButtons;

		if (btnPressed3 = 4)
		{
			lift = 0;
			displayLCDCenteredString(0,"No Lift? Ok...");
			displayLCDCenteredString(1,"Blue, Right, No Lift");

			if (red == 0 && left == 0 && lift == 0)
			{
				bluerightnolift = 1;
				redleftlift = 0;
			}
		}
	}
}

The error message was “Executable statements not valid in ‘main’ declaration block.” and you can easily see that the if statement starting on line 64 is outside of the “pre_auton” function. This is most likely because you forgot an open curly brace for the if statement starting on line 57. After adding that open curly brace, the if statement starting on line 64 would then be inside the “pre_auton” function, and the only thing missing would be a close curly brace at the very end to close out the function.

However, you also appear to have one other small error that will simply affect the performance of your code, rather than the compilation. The if statement starting on line 79 has the condition “btnPressed3 = 4” which first sets the variable “btnPressed3” equal to 4, then causes the condition to evaluate to “4” which (because any non-zero integer is considered “true”) evaluates to true, meaning that if statement will always evaluate to true, and its code will always be executed. I assume that you meant to have the condition “btnPressed3 == 4”.

Here is what your code with those changes would look like:

#pragma config(UserModel, "E:/Robotics/2831 C SFMS 2016-2017/Main Program Robot C/Program/Motor And Sensor Setup/setup.h")
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c" //Main competition background code...do  not modify!

int btnPressed1;
int btnPressed2;
int btnPressed3;
int red;
int left;
int lift;
int redleftlift;
int bluerightnolift;

/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////

void pre_auton()
{

	bStopTasksBetweenModes = true;

	bLCDBacklight = 1;
	clearLCDLine(0);
	clearLCDLine(1);
	displayLCDCenteredString(0, "Red or Blue?");
	btnPressed1 = nLCDButtons;
	if( btnPressed1 == 1)
	{
		red = 1;
		displayLCDCenteredString(0, "Red? Ok...");
		displayLCDCenteredString(1, "Left or Right?");
		btnPressed2 = nLCDButtons;
		if (btnPressed2 == 1)
		{
			left = 1;
			displayLCDCenteredString(0, "Left? Ok...");
			displayLCDCenteredString(1, "Yes Lift. No Lift");
			btnPressed3 = nLCDButtons;
			if (btnPressed3 == 1)
			{
				lift = 1;
				displayLCDCenteredString(0,"Red, Left, Lift");
				if( red == 1 && left == 1 && lift == 1)
				{
					redleftlift = 1;
					bluerightnolift = 0;
				}
			}
		}
	}
	if (btnPressed1 == 4)
	{
		red = 0;
		displayLCDCenteredString(0,"Blue? Ok...");
		displayLCDCenteredString(1,"Left or Right?");
		btnPressed2 = nLCDButtons;

		if (btnPressed2 == 4)
		{
			left = 0;
			displayLCDCenteredString(0,"Right? Ok...");
			displayLCDCenteredString(1,"Yes Lift. No Lift");
			btnPressed3 = nLCDButtons;

			if (btnPressed3 == 4)
			{
				lift = 0;
				displayLCDCenteredString(0,"No Lift? Ok...");
				displayLCDCenteredString(1,"Blue, Right, No Lift");

				if (red == 0 && left == 0 && lift == 0)
				{
					bluerightnolift = 1;
					redleftlift = 0;
				}
			}
		}
	}
}

Here’s a “groaner” but it is a good one to get new kids thinking about how programming works (obviously not Robot C code).

A programmer is going to the grocery store and his wife tells him, “Buy a gallon of milk, and if there are eggs, buy a dozen.” So the programmer goes, buys everything, and drives back to his house. Upon arrival, his wife angrily asks him, “Why did you get 13 gallons of milk?” The programmer says, “There were eggs!”

public int getNumberOfMilkToBuy(bool storeHasEggs)
{
int milkToBuy = 1;

if(storeHasEggs)
    milkToBuy += 12;

return milkToBuy;

}

Cute. I’m going to have to use that!

Thank you EVERYONE!!! This really helped!