It has no errors or warnings but nothing is working what could be the problem and the assignment says that I need to a finish commenting the function header blocks. ( i don't know what that is and I don't know if this is the reason that it is not working)

#include <iostream>
using namespace std;

// Constant for array sizes
const int SIZE = 20;

// Function prototypes
int bubbleSort(long [], int);  
int selectionSort(long [], int);

int main()
{
   int exchanges; // Number of exchanges made

   // Two arrays with identical values
   long accounts1[SIZE] =
      { 5658845,  4520125,  7895122,
        8777541,  8451277,  1302850,
        8080152,  4562555,  5552012,
        5050552,  7825877,  1250255,
        1005231,  6545231,  3852085,
        7576651,  7881200,  4581002 };
        
   long accounts2[SIZE] = 
      { 5658845,  4520125,  7895122,
        8777541,  8451277,  1302850,
        8080152,  4562555,  5552012,
        5050552,  7825877,  1250255,
        1005231,  6545231,  3852085,
        7576651,  7881200,  4581002 };
        
   // Sort accounts1 with bubble sort. The function
   // returns the number of exchanges made.
   exchanges = bubbleSort(accounts1, SIZE);
   
   // Display the number of exchanges made by the
   // bubble sort.
   cout << "\n" << exchanges 
        << " exchanges were made by Bubble Sort."
        << endl;

   // Sort accounts2 with selection sort. The function
   // returns the number of exchanges made.
   exchanges = selectionSort(accounts2, SIZE);
   cout << "\n" << exchanges 
        <<  " exchanges were made by Selection Sort." 
        << endl;

   return 0;
}

int bubbleSort(long array[], int size)
{
   bool swap;
   long temp;
   int  exchanges = 0;

   do
   {
      swap = false;   // No swaps made yet on this pass.

for (int count = 0; count < (size -1); count++)
{
	if (array[count] > array[count + 1])
	{
		temp = array[count];
		array[count] = array[count + 1];
		array[count + 1] = temp;
		swap = true;
		
	}
}
   } while (swap);  // Same as  while (swaps == true);

   return exchanges;
}


int selectionSort(long array[], int size)
{
   int  startScan,    // Array indexes to be compared
        minIndex,
        exchanges = 0;
   long minValue;
  

    void selectionSort(int array[], int size);

	for (startScan = 0; startScan < (size - 1); startScan++)
	{
		minIndex = startScan;
		minValue = array[startScan];
		for(int index = startScan +1; index < size; index++)
		{
			if (array[index] < minValue)
			{
				minValue = array[index];
				minIndex = index;
			}
		}
		array[minIndex] = array[startScan];
		array[startScan] = minValue;
	}

	{      
      // Move values to their new positions
      array[minIndex]  = array[startScan];
      array[startScan] = minValue;
      // Add the line to increment the number of exchanges.
	  exchanges++;

   } 
   return exchanges;
}

Works fine for me. It says 0 exchanges were made by bubble sort, and 1 exchanges was made by selection sort.

Also, what's this? " cout << "\n" << exchanges ". It is better practice to use 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.