expected unqualified-id before ' { ' token

this error keeps appearing : expected unqualified-id before ' { ' token
#include<iostream.h>

{
int x[100],n;
void switch (int &a, int &b)
{int aux=a;a=b;b=aux}
void divide (int s; int d; int &m)
{int i=s; j=d; pi=0; pj=1;
while (i<j)
{if (x[i]>x[j]){switch (x[i],x[j]);
switch (pi, pj);}
i=i+pi; j=j-pj;}
m=i;}
void quicksort (int s, int d)
{int m;
if (s<d){divide (s,d,m); quicksort (s,m-1);
quicksort (m+1,d);}}
int main ()
{int i;
cout<<"n= ";
cin>>n;
for (i=1;i<=n;i++)
{cout<<"x["<<i<<"]= ";
cin>>x[i];}
quicksort (1,n);
cout<<"vectorul sortat"<<endl;
for(i=1;i<=n;i++)
cout<<x[i]<<" ";}
return 0;
}
If you indent your code (use code tags) it may be easier to see what is going on but it looks like the { at the top of the code that is causing the problem. It simply shouldn't be there...
Last edited on
Is that your entire code?

I agree it would help if you used the code tags, but i've had a look and spotted no namespace at the beginning.. If you just didn't post all your code then this may be redundant, but I can't tell from what you've posted.

there are more errors in the code, but this gets rid of the one you had.
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>

using namespace std;

int x[100],n;

void switch1 (int &a, int &b)
{
	int aux=a;a=b;b=aux;
}
void divide (int s; int d; int &m)
{
	int i=s; j=d; pi=0; pj=1;
	while (i<j)
	{
		if (x[i]>x[j])
		{
			switch (x[i],x[j]);
			switch (pi, pj);
		}
		i=i+pi; j=j-pj;
	}
		m=i;
}
void quicksort (int s, int d)
{
	int m;
	if (s<d)
	{
		divide (s,d,m); quicksort (s,m-1);
		quicksort (m+1,d);
	}
}
int main ()
{
	int i;
	cout<<"n= ";
	cin>>n;
	for (i=1;i<=n;i++)

	{
		cout<<"x["<<i<<"]= ";
		cin>>x[i];
	}
	quicksort (1,n);
	cout<<"vectorul sortat"<<endl;
	for(i=1;i<=n;i++)
	cout<<x[i]<<" ";
}
is
void divide (int s; int d; int &m)
should be
void divide (int s, int d, int &m)

is
int i=s; j=d; pi=0; pj=1;
should be
int i=s, j=d, pi=0, pj=1;
thank you ahoysailor and chriscpp. I combined the program one of you gave me with the corrections of the other one, and it finally worked! so...thanks!
Topic archived. No new replies allowed.