0

I get this error, but I can't find where I forgot a paren / bracket...

int SUM1 = 0; if ( (length == 13) || (length == 15) ) { for (int a = 1; a < length; a++2) { int prodig = name[a] * 2; sprintf(dist, "%d", prodig); if (strlen(dist) == 2) { SUM1 = SUM1 + dist[0] + dist[1]; } else { SUM1 += dist[0]; } }

}

if (length == 16)
{
    for (int a = 1; a < length + 1; a++2)
    {
        int prodig = name[a] * 2;
        sprintf(dist, "%d", prodig);
        if (strlen(dist) == 2)
        {
            SUM1 = SUM1 + dist[0] + dist[1];
        }
        else
        {
            SUM1 += dist[0];
        }
    }
}

Error:

credit.c:21:40: error: expected ')'

    for (int a = 1; a < length; a++2)
                                   ^

credit.c:21:13: note: to match this '('

    for (int a = 1; a < length; a++2)


        ^

credit.c:39:44: error: expected ')' for (int a = 1; a < length + 1; a++2) ^ credit.c:39:13: note: to match this '('

    for (int a = 1; a < length + 1; a++2)
0

Sometimes, the compiler detects a problem but gives a misleading error message. It isn't a mismatch of parentheses, it's a problem with the code. It was expecting to find the parentheses there and found something else instead. Look at the line:

for (int a = 1; a < length; a++2)

The problem lies in the last clause of the for statement. a++2 is invalid. The increment operator, ++ can't be followed by that 2. It increments the preceding by 1 and only 1. If you want to actually increment by 2, you need something different, like a = a + 2.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .