Rezabrya
Rezabrya

Reputation: 11

Primary expression C++ error

I have to write some programs for a class final and I'm running into an error that I can't figure out. I have checked the syntax in this program many times and it isn't very long so I don't know why I can't find it. When I try and compile, I get an error that says "expected primary-expression before '}' token". It says it's in line 23. Can anyone shed some light on what might be going on?

#include <iostream>
using namespace std;

int main()
{
    int sumOfPrimes = 2;

    for (int x=3; x<2000000; x++)
    {
        for (int y=2; y<x; y++)
        {
            if (x % y == 0)
            {
                goto break1;
            }
        }
        sumOfPrimes += x;
        break1:
    }

    cout << sumOfPrimes << endl;

    return 0;
}

Upvotes: 1

Views: 40

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 992847

You need to add a statement after a label. The null statement ; works fine:

break1: ;

Upvotes: 1

Related Questions