error:expected ; before } token

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<fstream>
#include<new>
using namespace std;

main()
{
    int i,N,C,L,j,k,count;
    int *p;
    ifstream filein ("hello.txt");
    filein >> N;
    for(count = 1; count<= N; count++)
      {
        filein >> C;
        filein >> L;

        p = new (nothrow) int [L];
          for(i=0;i<L;i++)
           {
             filein >> p[i];
           }
        for (j=0;j<L;j++)
        {
            for(k=j+1;k<L; k++)
            {
                if (p[j]+p[k]==C)
                {
                    if(j<k)
                      {
                        cout  << "Case # "<< count << ": " << j+1 << " " << k+1 << "\n";
                        goto bye;
                      }
                    else
                      {
                        cout << "Case # "<< count << ": " << k+1 << " " << j+1 << "\n";
                        goto bye;
                      }
                }
            }

        }
          bye:
      }

    delete[] p;
    return 0;

}



upon compiling i get the following error in line 43:
error:expected ; before } token
i am unable to understand the cause of the error.
please suggest the necessary changes.
Last edited on
This is the only thing I saw wrong:

line 6 should be:
int main()

Will put it in Kate and see if I get any compiling errors

E: Found it!
below the label 'bye' put break;
That should fix it
Last edited on
yes it did..
but it comes out of the loop and gives only one answer as follows

Case #1: 2 3

the solution should be something as follows,

Case #1: 2 3
Case #2: 1 4
Case #3: 4 5

that is my program now exits from the loop without completing all the iterations
Ok then instead of putting break, put continue instead
I believe it it is cuz bye is still in the for loop, so your for loop continues to execute. Try to rewrite w/o using goto. Instead of goto, set your for loop variable to beyond its' end point, that way it will exit.
> Ok then instead of putting break, put continue instead
Or just ;
As the compiler already told you `error:expected ; before } token'

PS: ¿when will line 35 execute?

Also, you are leaking memory (¿is it so hard to indent the code?)
Topic archived. No new replies allowed.