error: expected unqualified-id before ' { ' token

this error keeps appearing whenever i try to compile this program:
error: expected unqualified-id before ' { ' token


#include<iostream.h>
typedef int stiva[100];
int n,i;
stiva st;
void init (int k);
{st[k]=0;
int successor
(int k);
{if(st[k]<n)
{st[k]=st[k]+1;
return 1;}
else return 0;}
int valid
(int k);
{for(i=1;i<k;i++)
if(st[k]==st[i])return 0;
return 1;}
int solution (int k)
{return k==n;}
void tipar()

{for(int i=1;i<=n;i++)
cout<<st[i]<<" ";
cout<<endl;}
void bt (int k)
{init(k);
while (successor(k))
if (valid(k))
if(solution(k)) tipar();
else bt(k+1);}
void main()

{cout<<"n= ";
cin>>n;
bt(1);}
}
1
2
3
4
5
6
7
void init (int k); // THERE SHOULD BE NO SEMI-COLON HERE
{st[k]=0;
int successor 
(int k);
{if(st[k]<n)
{st[k]=st[k]+1;
return 1;}


I take it this is an attempt to define a function. It's wrong, and the definition of the next function, valid, is stuck in the middle of it. Go back and format your code properly so that you can see where you're mixing all your function together into one big mess.

Also, I've marked above where there should be no semi-colon.

http://cplusplus.com/doc/tutorial/functions/
right...well...the problem is that my teacher gave me this program, and, at first it had about 10 errors, which i fixed..but i have no idea what i am supposed to do now...
Start by reformatting it correctly so you can see it clearly. Then you'll be able to fix the errors. You professor is using outdated C++ code from over a decade ago, which isn't going to help. I bet you're using Dev-Cpp as well.

1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream.h>
typedef int stiva[100];
int n,i;
stiva st;
void init (int k);
{
  st[k]=0;
  int successor (int k);
  {
     if(st[k]<n)
     ....
     ....
yes...sorry i forgot to mention that.
i still can't seem to get it right...i can't figure out what the problem is...
The problem is that the code is a mess with functions being defined in the middle of other functions with syntax errors all over the place.
and i have no idea how to create it again...or correct it, for that matter....
Topic archived. No new replies allowed.