hi guys!!! i have written small program here about customers, its for my assignment, emmm there's a small problem, i am using merge sort to sort customers in order by their ID, the only thing i dont know how to do i how would i pass ID into merge sort, so it will use it as sorting parameter, program runs, but doesn't show the correct output!!!if anyone know the solution for it, please help me with it.
thanks in advance!!

here' the code:

#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
#include <string>
using namespace std;

struct student
{   
    int ID;
	string name;
	string address;
	int courseCode;
    string courseTitle;	
};
typedef struct student S;

//***SORTING FUNCTION***
//int a[50];

void merge(int,int,int);
void merge_sort(int low,int high);
int ID[10];
//***SORTING FUNCTION***

//*** STUDENT DETAILS FUNCTION***
void enterDetails(S * sArray, int numStudents);
void printDetails(S * sArray, int numStudents);
//***STUDENT DETAILS FUNCTION***
//-----------------------------------------------
int main()
{
    int menuChoice = 0;
	int numStudents;
	cout << "Enter how many students do you require: " << endl;
	cin >> numStudents;
	system("CLS");
 	S * sArray = new S[numStudents];
 	
 	int i;
    while (menuChoice != 4)
	{
		cout << "\n" << setw (61) << "*** CUSTOMER DETAILS TABLE ***\n\n" << endl;   
		cout << setw (50) << "1 -- Add New Cutomer\n" << endl;
		cout << setw (57) << "2 -- Display Customer Table\n" << endl;
		cout << setw (48) << "3 -- Sort Students\n" << endl;
		cout << setw (52) << "4 -- Quit the program\n\n" << endl;
		cout << setw (54) << " Please make your choice: "; 
        
		cin >> menuChoice;
        system("CLS");	

		if (menuChoice == 1)
		{
           cin.ignore();  //int following a string
 	       for(int i =0; i < numStudents; i++)
	       {
		    cout << setw (43) << "Enter Student "<<i+1<<" Name: ";
		    getline(cin, sArray[i].name);
		    cout << setw (47) << "Enter Student ID: ";
		    cin >> sArray[i].ID;
		    cout << setw (52) <<"Enter Student Address: ";
		    cin >> sArray[i].address;
		    cout << setw (48) <<"Enter Course Code: ";
		    cin >> sArray[i].courseCode;
		    cout << setw (49) <<"Enter Course Title: ";
		    cin >> sArray[i].courseTitle;
		    
		    system("CLS");		
		    cin.ignore();//int following a string
	       }
		}		
		else if (menuChoice == 2)
		{
           cout << "ID \t" << "Name \t\t" << "Address \t" << "Course Code \t" << "Course Title \t" << endl;   
		   for(int i =0; i < numStudents; i++)
           {
            cout << sArray[i].ID << "\t" << sArray[i].name << "\t\t" << sArray[i].address << "\t\t" << sArray[i].courseCode << "\t\t" << sArray[i].courseTitle << endl;
            cin.ignore();
           }
           system("pause");
           system("CLS");
        }
         else if(menuChoice == 3)
         {
              int ID,i;

              /*cout << "********************************************************************************" << endl;
              cout << setw(50) << " MERGE SORT PROGRAM " << endl;
              cout << "********************************************************************************" << endl;
              cout<<endl<<endl;
              cout << "Please Enter THE NUMBER OF ELEMENTS you want to sort [THEN PRESS ENTER]:" << endl;
              cin>>numStudents;
              cout<<endl;
              cout << "Now, Please Enter the ( "<< numStudents <<" ) numbers (ELEMENTS) [THEN PRESS ENTER]:" << endl;
              for(i=1;i<=numStudents;i++)
              {
               cin>>ID[i] ;
              }
               merge_sort(1,numStudents);
               cout << endl;
               cin.get();
               */
               cout << "So, the sorted list (using MERGE SORT) will be :"<<endl;
               cout << endl << endl;

               for(i=1;i<=numStudents;i++)
               cout << ID << "	";

               cout << endl << endl << endl << endl;
               system("pause");
              
         }
	}
 return 0;	 
 	enterDetails(sArray, numStudents);
 	printDetails(sArray, numStudents);
}
//----------------------------------------------
void enterDetails( S * sArray, int numStudents)
{
	cin.ignore();  //int following a string
 	for(int i =0; i < numStudents; i++)
	{
		cout << "Enter Student Name: "<< i+1 << endl;
		getline(cin, sArray[i].name);
		cout << "Enter Student ID: " << endl;
		cin >> sArray[i].ID;
		cout << "Enter Student Address: " << endl;
		cin >> sArray[i].address;
		cout << "Enter Course Code: " << endl;
		cin >> sArray[i].courseCode;
		cout << "Enter Course Title: " << endl;
		cin >> sArray[i].courseTitle;
		
		cin.ignore();//int following a string
	}
    //system("pause");	
}

void printDetails( S * sArray, int numStudents)
{
  for(int i =0; i < numStudents; i++)
   {
    system("pause");
    
    
    cout << "Name \t" << sArray[i].name << endl;
    cout << "ID \t" << sArray[i].ID << endl;
    cout << "Address \t" << sArray[i].address << endl;
    cout << "Course Code \t" << sArray[i].courseCode << endl;
    cout << "Course Title\t" << sArray[i].courseTitle << endl;
    cin.ignore();
   }
}

void merge_sort(int low,int high)
{       
 int mid;
 if(low<high)
 {
  mid=(low+high)/2;
  merge_sort(low,mid);
  merge_sort(mid+1,high);
  merge(low,mid,high);
 }
}
void merge(int low,int mid,int high)
{
 int ID[10];    
 int h,i,j,b[50],k;
 h=low;
 i=low;
 j=mid+1;

 while((h<=mid)&&(j<=high))
 {
  if(ID[h]<=ID[j])
  {
   b[i]=ID[h];
   h++;
  }
  else
  {
   b[i]=ID[j];
   j++;
  }
  i++;
 }
 if(h>mid)
 {
  for(k=j;k<=high;k++)
  {
   b[i]=ID[k];
   i++;
  }
 }
 else
 {
  for(k=h;k<=mid;k++)
  {
   b[i]=ID[k];
   i++;
  }
 }
 for(k=low;k<=high;k++) ID[k]=b[k];
}

is there anyone who would be able to help me out with this, please...the problem i am having is merge sort and binary search. i just dont know how to pass in dynamic array into function, so it will use student ID, to sort and search for!!!real headache for me. Thanks in advance!
heres the new code with merge sort and binary search:

#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
#include <string>
using namespace std;

struct student
{   
    int ID;
	string name;
	string address;
	int courseCode;
    string courseTitle;	
};
typedef struct student S;

//CLASS DECLARATION
class search
{
int i,x,first,last,mid;
int a[10];
int numStudents;
char search;
public:
void binary(S * sArray);
};

//***SORTING FUNCTION***
//int ID[10];
void merge(int,int,int);
void merge_sort(int low,int high);
//***SORTING FUNCTION***

//*** STUDENT DETAILS FUNCTION***
void enterDetails(S * sArray, int numStudents);
void printDetails(S * sArray, int numStudents);
//***STUDENT DETAILS FUNCTION***
//-----------------------------------------------
int main()
{
    int menuChoice = 0;
	int numStudents;
	cout << "Enter how many students do you require: " << endl;
	cin >> numStudents;
	system("CLS");
 	S * sArray = new S[numStudents];
 	
 	int i;
    while (menuChoice != 5)
	{
		cout << "\n" << setw (61) << "*** CUSTOMER DETAILS TABLE ***\n\n" << endl;   
		cout << setw (50) << "1 -- Add New Cutomer\n" << endl;
		cout << setw (57) << "2 -- Display Customer Table\n" << endl;
		cout << setw (48) << "3 -- Sort Students\n" << endl;
		cout << setw (48) << "4 -- Search Students\n" << endl;
		cout << setw (52) << "5 -- Quit the program\n\n" << endl;
		cout << setw (54) << " Please make your choice: "; 
        
		cin >> menuChoice;
        system("CLS");	

		if (menuChoice == 1)
		{
           cin.ignore();  //int following a string
     	   for(int i =0; i < numStudents; i++)
	       {
		    cout << setw (43) << "Enter Student "<<i+1<<" Name: ";
		    getline(cin, sArray[i].name);
		    cout << setw (47) << "Enter Student ID: ";
		    cin >> sArray[i].ID;
		    cout << setw (52) << "Enter Student Address: ";
		    cin >> sArray[i].address;
		    cout << setw (48) << "Enter Course Code: ";
		    cin >> sArray[i].courseCode;
		    cout << setw (49) << "Enter Course Title: ";
		    cin >> sArray[i].courseTitle;
		    
		    system("CLS");		
		    cin.ignore();//int following a string
	       }
		}		
		else if (menuChoice == 2)
		 {
           printDetails(sArray, numStudents);                      
           system("pause");
           system("CLS");
         }
        else if(menuChoice == 3)
         {
           //int sArray[i].ID,i;
           int numStudents,i;
           cout << "So, the sorted list (using MERGE SORT) will be :"<<endl;
           cout << endl << endl;
           
           for(i=1; i<=numStudents; i++)
           //{
           cout << sArray[i].ID << "	";
           //}
           //merge_sort(1,numStudents);
           
           cout << endl << endl << endl << endl;
           system("pause");
           system("CLS");   
         }
        else if(menuChoice == 4)
         {
           class search obj; //OBJECT DECLARATION
           int choice;
           char ch = 'c';
           do
           {
             system ("CLS");
             cout << setw(45) << " ***--MENU--***  " << endl;
             cout << setw(45) << " 1.Binary Search " << endl;
             cout << setw(44) << " 2.Exit Program " << endl << endl;
             cout << setw(48) << " Enter your choice: " << endl;
             cin >> choice;

            switch(choice)
            {
             case 1:
             system("CLS");
             obj.binary(sArray);
             break;
             default:
             cout << " Invalid choice " << endl;
        
             case 2:
             system("CLS");
            }
             cout << " Press *C* to continue, any other key to exit " << endl;
             cin >> ch;
            }//do end
           while(( ch == 'c' )||( ch == 'C' ));             
           system("pause");
           //system("CLS");
           //cin.ignore();
         }//else end
	}//while end
 return 0;	 	
}//main end
//----------------------------------------------
void enterDetails(S * sArray, int numStudents)
{
    enterDetails(sArray, numStudents);
	cin.ignore();  //int following a string
}
void printDetails(S * sArray, int numStudents)
{
    cout << "ID \t" << "Name \t\t" << "Address \t" << "Course Code \t" << "Course Title \t" << endl;   
	for(int i =0; i < numStudents; i++)
     {
      cout << sArray[i].ID << "\t" << sArray[i].name << "\t\t" << sArray[i].address << "\t\t" << sArray[i].courseCode << "\t\t" << sArray[i].courseTitle << endl;
      cin.ignore();
     }                     
}
void merge_sort(int low,int high)
{     
 int mid;
 if(low<high)
 {
  mid=(low+high)/2;
  merge_sort(low,mid);
  merge_sort(mid+1,high);
  merge(low,mid,high);
 }
}
void merge(int low,int mid,int high)
{  
 //S * sArray[0];  
 int ID[0];
 int h,i,j,b[50],k;
 h=low;
 i=low;
 j=mid+1;
 while((h<=mid)&&(j<=high))
 {
 if(ID[h]<=ID[j])
  {
   b[i]=ID[h];
   h++;
  }
  else
  {
   b[i]=ID[j];
   j++;
  }
  i++;
 }
 if(h>mid)
 {
  for(k=j;k<=high;k++)
  {
   b[i]=ID[k];
   i++;
  }
 }
 else
 {
  for(k=h;k<=mid;k++)
  {
   b[i]=ID[k];
   i++;
  }
 }
 for(k=low;k<=high;k++) ID[k]=b[k];
}
void search::binary(S * sArray)
{
 int ID;    
 first=0;
 last=9;
 search='f';
 /*cout << " Please Enter the Array of Numbers in sorted order (min 10) : " << endl;
 for(i=0;i<10;i++)
  {
   cout<<"\t\t";
   cin>>a[i];
  }*/
 cout << " Please Enter the Number to be searched : " << endl;
 cin>>sArray[i].ID;
 while((first<=last)&&(search=='f'))
  {
   mid=(first+last)/2;
    if(a[mid]==sArray[i].ID)
     {
      i=mid;
      search='t';
     }
    if(a[mid]<sArray[i].ID)
     first=mid+1;
    if(a[mid]>sArray[i].ID)
     last=mid-1;
  }
 if(search=='t')
  cout << " The Number " << sArray[i].ID << " was found at the position number " << i+1 << endl;
 if(search=='f')
  cout << " Sorry! Number not found " << endl;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.