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) 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.

You are watching: C++ control reaches end of non-void function


Skynet June 25, 2021, 7:11pm #2

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 */}
StevenNet June 25, 2021, 7:14pm #3
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: *** Error 1

make process closed with exit code : 2

and yes i named my project slef-rulling potato


StevenNet June 25, 2021, 7:15pm #4

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) 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;}


Skynet June 25, 2021, 7:20pm #5

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

See more: Comics Y Memes En Español 2016 Meme Wars, Comics Y Memes


StevenNet June 25, 2021, 7:22pm #6

Self-rulling Potato.iqcpp (2.9 KB)


Skynet June 25, 2021, 7:26pm #7

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


StevenNet June 25, 2021, 7:28pm #8

sorry i dont get what you want me to do


Skynet June 25, 2021, 7:28pm #9

Just copy and paste the main.cpp file.


StevenNet June 25, 2021, 7:31pm #10

how to i find the main.ccp file


StevenNet June 25, 2021, 8:01pm #11

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

*


Foster June 26, 2021, 11:02am #12

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


3 Likes
Home Categories FAQ/Guidelines Terms of Service Privacy Policy

Powered by Discourse, best viewed with JavaScript enabled