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.
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 */
}
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;
}
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.
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?
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.
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
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
system
Closed
June 26, 2022, 11:03am
13
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.