Void Function Problem, Function definition is not allowed here

Im very new to the whole programming gig and I wanted to test out code that would allow me to actually program in distances for our autons. I asked around and I got some sample code but there is an error saying “Function definition is not allowed”

Heres the portion of the code where the error is:

const float WHEEL_DIAMETER = 4;
const float WHEEL_CIRCUMFERENCE = WHEEL_DIAMETER * 3.1416;
const float GEAR_RATIO = 1;
const int AUTON_DRIVE_PCT = 50;
void driveForward(float inches) {//The error is right here
float inchesPerDegree = WHEEL_CIRCUMFERENCE / 360;
float degrees = inches / inchesPerDegree;

LDF.startRotateFor(degrees * GEAR_RATIO, vex::rotationUnits::deg,
                   AUTON_DRIVE_PCT, vex::velocityUnits::pct);
LDB.startRotateFor(degrees * GEAR_RATIO, vex::rotationUnits::deg,
                   AUTON_DRIVE_PCT, vex::velocityUnits::pct);
RDF.rotateFor(degrees * GEAR_RATIO, vex::rotationUnits::deg,
              AUTON_DRIVE_PCT, vex::velocityUnits::pct);
RDB.rotateFor(degrees * GEAR_RATIO, vex::rotationUnits::deg,
              AUTON_DRIVE_PCT, vex::velocityUnits::pct);

}

you probably define a function in another function. Show your whole code with enclose by with “```”

Heres everything leading to the user control, sorry my computers slow and would take forever to paste everything

/----------------------------------------------------------------------------/
/* /
/
Module: main.cpp /
/
Authors: Vivek Patel /
/
Created: Sun Dec 22 2019 /
/
Description: Competition Template /
/
/
/
----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// LimitSwitchA limit A
// Inertial inertial 12
// ---- END VEXCODE CONFIGURED DEVICES ----

#include “vex.h”

using namespace vex;

// A global instance of competition
competition Competition;

/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions */

void pre_auton(void) {

// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
vex::inertial Inertial(vex::PORT12);
Inertial.calibrate();

while (Inertial.isCalibrating()) {
wait(100, msec);
}

const float WHEEL_DIAMETER = 4;
const float WHEEL_CIRCUMFERENCE = WHEEL_DIAMETER * 3.1416;
const float GEAR_RATIO = 1;
const int AUTON_DRIVE_PCT = 50;
void driveForward(float inches) {
float inchesPerDegree = WHEEL_CIRCUMFERENCE / 360;
float degrees = inches / inchesPerDegree;

LDF.startRotateFor(degrees * GEAR_RATIO, vex::rotationUnits::deg,
                   AUTON_DRIVE_PCT, vex::velocityUnits::pct);
LDB.startRotateFor(degrees * GEAR_RATIO, vex::rotationUnits::deg,
                   AUTON_DRIVE_PCT, vex::velocityUnits::pct);
RDF.rotateFor(degrees * GEAR_RATIO, vex::rotationUnits::deg,
              AUTON_DRIVE_PCT, vex::velocityUnits::pct);
RDB.rotateFor(degrees * GEAR_RATIO, vex::rotationUnits::deg,
              AUTON_DRIVE_PCT, vex::velocityUnits::pct);

}
}
/---------------------------------------------------------------------------/
/* Autonomous Task */

void autonomous(void) {

// Drive Motors
vex::motor RDF(vex::PORT10, vex::gearSetting::ratio18_1, false);
vex::motor RDB(vex::PORT20, vex::gearSetting::ratio18_1, true);
vex::motor LDF(vex::PORT1, vex::gearSetting::ratio18_1, true);
vex::motor LDB(vex::PORT11, vex::gearSetting::ratio18_1, false);
// Lift Motors
vex::motor LL(vex::PORT13, vex::gearSetting::ratio36_1, true);
vex::motor RL(vex::PORT19, vex::gearSetting::ratio36_1, false);
// Intake Motors
vex::motor CLR(vex::PORT6, vex::gearSetting::ratio36_1, false);
vex::motor CLL(vex::PORT3, vex::gearSetting::ratio36_1, false);
// Inertial
vex::inertial Inertial(vex::PORT12);
// Controller
vex::controller Controller1 = vex::controller();
}

/---------------------------------------------------------------------------/
/* User Control Task */

you define

void driveForward(float inches) 

inside

void pre_auton(void)

just move the definition of function driveForward outside of pre_auton

1 Like

Yeah I think I just got it to work, thanks a bunch I didn’t realize that could’ve been the issue. Forum works magic