Matteo
Matteo

Reputation: 67

Getting a syntax error on a variable declaration in C

I see a syntax error when I run the debugger on the two variables I declare in CLion. I commented the debugger errors it shows me in the lines of the two variables.

int sum3or5Multiples() {

    int sum = 0;    // sum: error: A syntax error in expression, near `/mt sum`.
    int multipleOf3;    // multipleOf3: error: A syntax error in expression, near `/mt multipleOf3`
    for (multipleOf3 = 0; multipleOf3 < 1000; multipleOf3 + 3) {
        sum = sum + multipleOf3;
    }
    int multipleOf5;
    for (multipleOf5 = 0; multipleOf5 < 1000; multipleOf5 + 5) {
        sum = sum + multipleOf5;
        if ((3 * multipleOf5) < 1000) {
            sum = sum - (3 * multipleOf5);
        }
    }
    return sum;
}

Upvotes: 2

Views: 1520

Answers (1)

Vlad from Moscow
Vlad from Moscow

Reputation: 311078

It seems you mean

multipleOf3 += 3

and

multipleOf5 += 5

instead of

multipleOf3 + 3

and

multipleOf5 + 5

With these changes the function compiles without errors.

Upvotes: 4

Related Questions