Error: control reaches end of non-void function

I’m working on this line code project in vexcode iq and whenever i build it i get an error control reaches end of non-void function

here is my code

#include “iq_cpp.h”

using namespace vex;

int error;
int output;
int input;

int myFunction(int Distance, int Heading, int Velocity, int Kp) {
leftMotor.setPosition(0, degrees);
rightMotor.setPosition(0, degrees);
if(Velocity > 0) {
while(leftMotor.position(degrees) < Distance) {
error = Heading - Gyro7.rotation();
output = error * Kp;
leftMotor.setVelocity(Velocity - output, percent);
rightMotor.setVelocity(Velocity + output, percent);
leftMotor.spin(forward);
rightMotor.spin(forward);
wait(20, msec);
}
}
else {
while(leftMotor.position(degrees) > Distance) {
error = Heading - Gyro7.rotation();
output = error * Kp;
leftMotor.setVelocity(Velocity - output, percent);
rightMotor.setVelocity(Velocity + output, percent);
leftMotor.spin(forward);
rightMotor.spin(forward);
wait(20, msec);
}
}
leftMotor.stop();
rightMotor.stop();
}

can you please tell me what this means and how to fix it thanks.

Because the functions type is int, you have to return something at the end of the function. To fix it you can just return 0, or you can change the type of the function to void.

int function() {
    /* Your code */
    return 0;
}

or

void function() {
    /* Your code */
}

thanks for the feedback but when i do that and compile it again the compiler has an error and i get this:

windows build for platform vexiq

“CXX src/main.cpp”

“LINK build/SelfrullingPotato.elf”

C:\Program Files (x86)\VEX Robotics\VEXcode IQ\sdk/vexiq\libviqrt.a(iq_main.c.obj): In function userInitialize': iq_main.c:(.text.userInitialize+0x28): undefined reference to main’

make: *** [vex/mkrules.mk:18: build/SelfrullingPotato.elf] Error 1

make process closed with exit code : 2

and yes i named my project slef-rulling potato

here is my new code:

#include “iq_cpp.h”

using namespace vex;

int error;
int output;
int input;

int myFunction(int Distance, int Heading, int Velocity, int Kp) {
leftMotor.setPosition(0, degrees);
rightMotor.setPosition(0, degrees);
if(Velocity > 0) {
while(leftMotor.position(degrees) < Distance) {
error = Heading - Gyro7.rotation();
output = error * Kp;
leftMotor.setVelocity(Velocity - output, percent);
rightMotor.setVelocity(Velocity + output, percent);
leftMotor.spin(forward);
rightMotor.spin(forward);
wait(20, msec);
}
}
else {
while(leftMotor.position(degrees) > Distance) {
error = Heading - Gyro7.rotation();
output = error * Kp;
leftMotor.setVelocity(Velocity - output, percent);
rightMotor.setVelocity(Velocity + output, percent);
leftMotor.spin(forward);
rightMotor.spin(forward);
wait(20, msec);
}
}
leftMotor.stop();
rightMotor.stop();
return 0;
}

Can you please upload the whole project? Please format your code blocks with ``` before and after to make your post more readable.

Self-rulling Potato.iqcpp (2.9 KB)

Thats just the configuration, if your all your code is in the main.cpp file can you upload that?

sorry i dont get what you want me to do

Just copy and paste the main.cpp file.

how to i find the main.ccp file

I did some research and I got the code to work without any errors thanks for all the help :grinning:

Hey, your answer got cut off on what the fix was, you want to repost that part please?

3 Likes