")" expected when i already have one. Please help

here is my code file if someone could please help me fix it. I would greatly appreciate it i’m trying to get the vision sensor to be able to determine distance but it keeps saying “)” expected in the area where i have my equation and I cant figure out how to fix it so if someone could please help me fix it i would be very appreciative.
vision sensor test program.vex (6 KB)

maybe line 69:
“… ; S++;);”

1 Like

nope still says expected “)”
any other idea of anything to try to do

A few suggestions (I can’t open the file on the computer I’m using):
In VCS, if you click on a bracket, it will highlight it’s matching bracket. Recommend starting at the top and checking where each open/close set it.
Another thing to check is that a bracket that you think you are using is not inside a comment
Also, do you have any typos - such as a square bracket when you should have a curved bracket

1 Like

Lines 59-71:

void distance(){
    for (int x = Vision.largestObject.originX; x++;);
    for (int y = Vision.largestObject.originY; y++;);
    for (int h = 5; h++;);
    for (int a = 0; a++;);
    for (int y = Vision.largestObject.originY, x = Vision.largestObject.originX, tan = y/x; tan++;);
    for (int y = Vision.largestObject.originY, x = Vision.largestObject.originX, tan = y/x, atan = tan^-1; atan++;);
    double inches (int h  5, int a  0, int y  Vision.largestObject.originY, int x  Vision.largestObject.originX, int tan  y/x, int atan  tan(-1*tan), int S  h*tan(a-atan((1-y/(200))*tan(23.5))); S++;);

For starters, you probably need a return type, but instead you have distance returning nothing: void.

Next up, none of your for loops are set up properly. The ones that don’t have other syntax errors will run indefinitely, except for the one involving a, but that’s more a fluke of the starting value that you chose rather than proper behavior. To boot, I’m not even sure what you were trying to use them for, as none of them do anything other than increment a variable.

Next up, line 68. This thing is a mess, overshadowed only by the following line 69. It’s another poorly setup for loop, for starters. Next up, the only reason it compiles is that you declare a bunch of variables in the initialization statement all of type int, and manage to do so in an order that doesn’t clash. The problem is that the scope of all of them is limited to the for loop that they are declared in, which has no body and so does nothing. It also likely doesn’t terminate, as the result of tan^-1 (tan XOR -1) is most often non-zero. (In C, the ^ operator is for XOR, not exponentiation.)

Line 69. double inches (somevalue); would work to declare inches with an initial value. That is, if anything comprising somevalue was an r-value that could be evaluated. But it isn’t:

int h  5,
int a  0,
int y  Vision.largestObject.originY,
int x  Vision.largestObject.originX,
int tan  y/x,
int atan  tan(-1*tan),
int S  h*tan(a-atan((1-y/(200))*tan(23.5)));

Is not a thing that can be evaluated. It doesn’t say anything coherent. It looks like it’s attempting to declare variables in an illegal position (can’t declare variables in the initialization value of another variable) without using any valid initialization syntax (int var = # or int var(#) would work if this were a valid place to declare variables, but int var # is invalid). You do that seven times, then seem to forget that you’re not setting up a for loop and finish with ;S++;), the same kind of improper for loop logic that you were using on the previous lines. Only you were initializing a variable, not setting up a for loop.

I think you need to brush up on your C++ syntax and not rely on compiler errors to tell you what to change.

To boot, the way you are handling button press events is also no good. Starting an unbroken while loop every time one of the buttons is pressed will proliferate the number of threads that you have going. Event handlers should run their code and exit promptly. You will need to remove the while loops from every function but main if you want this to work properly.

tl;dr it’s a much larger problem than an unmatched parenthesis


so the best thing to do is to completely restart from scratch .

Restarting from scratch without knowing why what you currently have is wrong won’t help. Knowing why what you have is wrong would show you that it’s not necessary to restart from scratch. (Assuming the trigonometry is correct once the other problems are corrected.)


So i should reread some C++ syntax and then use the new knowledge to fix the problem

1 Like

Yep. If you want an example of a program that uses functions to compute and return values, this one that I wrote in Robot Mesh Studio has two examples.


Also, instead of going for the big bang and writing 100 lines of code - take it in bite sized pieces. Get a small portion of the code to run then add to it. The theory is called " build a little, test a little." Its much easier to troubleshoot in small chunks.


If you want some fairly simple vision sensor code as a starting point, see this.

1 Like

i know how to code for the vision sensor i just was trying something that i have never done before cause i have it to where it can turn a motor when it sees red, it can draw a red rectangle that mimics the red block that the sensor can see on the brain screen, and where if a red object is on the right half of the vision sensors view that it will turn a motor to the left and vise-versa for the right side of the vision sensor i just had no idea what i was doing with the math stuff