Visual C++ error C2143: syntax error: missing ')' before 'constant'

18,312

Solution 1

I'm not quite sure if this is the same error that the compiler is giving you, but you have to put a '*' sign in front of the second '2' so that this:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2 * depth);

Becomes this:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) * 2 * depth);

Solution 2

Other posters have shown you the actual error in the statement, but please, split that up into multiple sub-statements that more clearly show what you are trying to do mathematically, because that function is going to cause you headaches in the future if you don't!

Solution 3

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) (the problem is here) 2 * depth);

Solution 4

Even though you have the right answer, I'm going to explain how you should have arrived at it.

When faced with an error in a long expression that you can't find, take the expression apart, piece by piece, until you find it.

In this case:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2 * depth);

becomes:

firsthalf = (1 - (2 * depth));
secondhalf = ((t - floor( t + 0.5 ) + 1 ) 2 * depth);   // Error appears on this line
coefficient[i] = firsthalf + secondhalf;

This eliminates the first part as the source of the error.

Next attempt:

exprA = (t - floor( t + 0.5 ) + 1 );
exprB = exprA * 2;
exprC = exprB * depth;   // Hmm.... this all worked.  Start putting it back together.
secondhalf = exprC;

Final attempt:

exprA = (( MY_TEST_CONSTANT ) 2 * depth);   // Error now becomes obvious.

Solution 5

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2(What is 2 doing here?) * depth);

Share:
18,312
Jonathan Deon
Author by

Jonathan Deon

Professional Software Developer based in Boston, MA, USA. Professional experience with Scala, Spark, Java technologies, SQL/Databases, Javascript, front-end technologies (HTML/CSS), various web services.

Updated on June 04, 2022

Comments

  • Jonathan Deon
    Jonathan Deon almost 2 years

    I'm getting an error in Visual C++ that is giving me a really hard time.

    The error is error c2143 reading: syntax error: missing ')' before 'constant'

    My code line is:

    coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2 * depth); 
    

    I have #include at the beginning of the file which should define the floor(double) function.

    a bit more explanation of the variables.

    double depth is a member variable of the class which this line can be found in.
    int i is an incrementing index value.
    double t is an incrementing value.

    What they do is really unimportant, but I wanted to clarify that all three are already defined as variables of basic types.

    I've gone through and verified that all the parentheses match up. I'm kind of at a loss as to what 'constant' the compiler is referring to. Any ideas?