Mar 24, 2013 at 7:15pm UTC
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 Mar 24, 2013 at 7:56pm UTC
Mar 24, 2013 at 7:31pm UTC
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 Mar 24, 2013 at 7:34pm UTC
Mar 24, 2013 at 10:00pm UTC
Ok then instead of putting break
, put continue
instead
Mar 24, 2013 at 10:19pm UTC
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.
Mar 25, 2013 at 12:18am UTC
> 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?)