Please can someone troubleshoot this for me "[Error] a function-definition is not allowed here before '{' token"

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
int arr[10],sup_num,choice;
string name;
string title;
cout<<"BOTHO DATA CAPTURING SYSTEM"<<endl;
cout<<"Welcome to Botho Library Services"<<endl;
cout<<"please enter your name: "<<endl;
cin>>name;
cout<<"please enter your title (mr/mrs/miss) "<<endl;
cin>>title;
cout<<"Hello "<<title<<"/t"<<name<<endl;
void read()
{
while(1)
{
cout<<"How many suppliers do you wish to compare? "<<endl
cin>>sup_num;
if((sup_num>0) && sup_num<=10))
break;
cout<<endl<<"The number of suppliers should range from 1 to 10! ";
}
cout<<"enter suplier quotes: "<<endl;
for(int i=0;i>sup_num;i++)
{
cout<<"SUPPLIER/t "<<i+1;
cin<<arr[i];
}
}
void bubble_sort()
{
for int i=1;i<sup_num;i++) //for the number of passes
{
for(int j=0;j<sup_num-1;j++)
{
if(arr[j]>arr[j+1])//if the elements are not in their correct order
{ //swap the elements
int temp;
temp=arr[j];
arr[j]=arr[j+1]
arr[j+1]=temp;
}
}
}
}


void swap(int x, int y)//swaps element x and y,used by quick sort
{
int temp;
temp=arr[x];
arr[x]=arr[y];
arr[y]=temp;
}
void insert_sort()
{
void select_sort()
void quik_sort(int low,int high)
{int pivot,i,j;
if(low>high)
return;
//partition the list into two
//less or equal to the pivot
//greator than the pivot
i=low+1;
j=high+1;
pivot=arr[low];
while(i<=j)
{
i++;
int cmp_count++; //number of comparisons
}
cmp_count++;
while((arr[j]>pivot) && (j>=low))
{j--;
cmp_count++;
}
cmp_count++;
if(i<j)
{
//swap the elements at index i and at j
swap(i,j);
int mov_count++;//number of data movements
}
}
if(low<j)
{
swap(low,j);//move the pivot to its correct position
mov_count++;
}
quick_sort(low,j-1)//quick sort elements on the left
quick_sort(j+1,high)//quick sort elements on the right
}
int getsize()
{
return(sup_num);
}
void display()
cout<<"sorted array elements";
for(int j=0;j<sup_num;j++)
{cout<<"suppliet at rank "<<j+1<<"is "<<arr[j]<<endl;
cout<<"number of comparisons: "<<cmp_count;
cout<<"number of data movements: "<<mov_count;
}



cout<<"This is the raw quotes with the rates";
cout<<"which sorting technique do you want to use?"<<endl;
cout<<"**********************************************************";
cout<<"1 BUBBLE SORT "<<endl;
cout<<"2 INSERTION SORT "<<endl;
cout<<"3 SELECTION SORT "<<endl;
cout<<"4 QUICK SORT "<<endl;
cout<<"***********************************************************";
cout<<"Enter your choice: "<<endl;
cin>>choice;
cout<<"The choosen sorting technique is: "<<choice<<endl;
switch(choice)
{
case 1: cout<<"You chose to use bubble sort"<<endl;
read();
bubble_sort();
display();
break;
case 2: cout<<"You chose to use insertion sort"<<endl;
read();
insert_sort();
display();
break;
case 3: cout<<"you chose to use selection sort "<<endl;
read();
select_sort();
display();
break;
case 4: cout<<"You chose to use quick sort "<<endl;
read();
quick();
display();
break;

case 5: cout<<" Exit"<<endl;
break;
default:
cout<<"invalid choice! "<<endl;

}
Could you edit your post to use [code] tags and indentation?

I'd guess, though, that you are probably trying to define a function inside another function, which isn't allowed.
From looking at the code, that's the exact issue. You cannot define functions from within main or any other function. That, and the second half of your code isn't even in main().
Thanx!!!
#its working

#include<iostream>
#include<conio.h>
using namespace std;

class Sorting
{
public:
int arra[10];
int arrb[10];
int sup_num;
string name;
string title;
void arr_keeper()

{
cout<<"please enter your name: "<<endl;
cin>>name;
cout<<"please enter your title (mr/mrs/miss) "<<endl;
cin>>title;
cout<<endl;
cout<<"************************************************************************************************"<<endl;
cout<<"BOTHO DATA CAPTURING SYSTEM"<<endl<<endl<<endl;
cout<<"Welcome to Botho Library Services"<<endl<<endl;
cout<<"**************************************************************************************************"<<endl;
cout<<endl<<endl;
cout<<"Hello "<<title<<"\t"<<name<<endl<<endl;
}

void accept() {
cout << "How many supplier quotes are to be entered..? \n\n";
cin >>sup_num ;
cout<<"\n";

if((sup_num == 5) &&(sup_num<=10))
cout<<"The quote entered is"<<sup_num<<"\n";

else
cout<<"number should be between 5 and 10\n";

for(int i = 0; i < sup_num; i++)
{

cout<<"SUPPLIER\t"<<i + 1 <<">\t";
cin >> arra[i];
arrb[i]= arra[i];
cout << endl;

}
}

void Copying()
{
for (int i=0; i<sup_num; i++)
{
arra[i]= arrb[i];
}
}

void Bubble_Sort()
{
for (int i = 1; i < sup_num; i++)
{
for (int j = 0; j < sup_num - i; j++)
{
if (arra[j] > arra[j + 1])
{
int temp;
temp = arra[j];
arra[j] = arra[j + 1];
arra[j + 1] = temp;
}
}
}
}
void display()
{
cout<<endl;
cout<<"------------------------------------------------------------------\n";
cout<<"Sorted array elements\n";
cout<<"------------------------------------------------------------------\n";

for (int j = 0; j < sup_num; j++)
{
cout <<arra[j]<<endl;
}
}

void Selection_Sort()
{

int i, j, minIndex, tmp;

for (i = 0; i < sup_num - 1; i++)
{

minIndex = i;

for (j = i + 1; j < sup_num; j++)

if (arra[j] < arra[minIndex])

minIndex = j;

if (minIndex != i) {

tmp = arra[i];

arra[i] = arra[minIndex];

arra[minIndex] = tmp;

}

}

}
void swaping(int x,int y)
{
int temp;
temp=arra[x];
arra[y]=temp;
}


void Insertion_Sort ( ){

int j, temp;

for (int i = i; i < sup_num; i++){
j = i;

while (j > 0 && arra[j] < arra[j-1]){
temp = arra[j];
arra[j] = arra[j-1];
arra[j-1] = temp;
j--;
}
}
}


void swap(int b, int c)
{
int temp;
temp=arra[b];
arra[b]=arra[c];
arra[c]=temp;
}

void Quick_Sort(int low, int high)
{
int cmp_count;
int mov_count;
int pivot, i, j;
if(low> high)
return ;

//divide the list into two part: one containing elements less or equal to pivot whilst the other containing elements greater than pivot

i=low+1;
j=high;
pivot=arra[low];

while(i<=j)
{
//search for an element greater than the pivot
while (( arra[i] <= pivot) && (i<=high))
{
i++;
cmp_count++;
}
cmp_count++;
//search for an element less than or equal to pivot
while((arra[j] > pivot )&& (j >=low))
{
j--;
cmp_count++;

}
cmp_count++;
if(i < j)// if the greater element is on the left of the smaller element
{

// swap the element at index i with the element at index j

swap(i,j);
mov_count++;

}
}

// j now contains the index of the last element in te sorted list
if (low <j)
{
swap(low,j);
mov_count++;
}
//sort the list on the left of the pivot using quick sort
Quick_Sort(low,j-1);
//sort the list on the right of the pivot using quick sort
Quick_Sort(j+1,high);
}


int getSize()
{
return(sup_num);
}
};
int main(){


Sorting OBJ;

OBJ.arr_keeper();
OBJ.accept();
char chosen;
while(true)
{

cout<< "************************** CHOSE THE METHOD YOU WANT TO USE*********************************\n";
cout<<"MENU\n";
cout<<"1.Bubble_Sort\n";
cout<<"2.Selection\n";
cout<<"3.Insertion\n";
cout<<"4.Quiksort\n";
cout<<"5.Exit\n";
cout<<"chosen method\n";
cin>>chosen;


switch (chosen)
{
case'1':
{
OBJ.Copying();
OBJ.Bubble_Sort();
OBJ.display();
break;
}
case'2':
{

OBJ.Copying();
OBJ.Selection_Sort();
OBJ.display();
break;
}
case'3':
{
OBJ.Copying();
OBJ.Insertion_Sort();
OBJ.display();
break;
}
case'4':
{
OBJ.Copying();
OBJ.Quick_Sort(0,OBJ.getSize() - 1);
OBJ.display();
break;
}
case'5':
{
exit(0);
break;
}
default:
{
cout<<"Error, bad input, quitting\n";
break;
}
{
cout<<"do you want to proceed..? press 0 to continue \n or press any key to exit. \n";
cout<<"********************************************* \n";
cin>>chosen;
if (chosen == 0)
continue;
else
break;
}
cin.get();


}
}
}
Topic archived. No new replies allowed.