#include <iostream>
using std::cout;
using std::endl;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
// Function Prototype
void selectionSort( int [], int );
int main()
{
// Given variable and constant declarations
const int SIZE = 10;
const int MAXRANGE = 1000;
int sortThisArray[ SIZE ] = {};
srand( time( 0 ) );
// Fill array with random numbers between 1-1000
int n[SIZE]={815,5,562,501,102,513,5,98,495,451};
// Display the unsorted array
cout<<"unsorted array is:"<<endl;
for (inti=0;i<SIZE;i++)
cout<<set(4)<<[i];
// Call the sorting array function
selectionSort( sortThisArray, SIZE );
// Display the sorted array
cout<<"Sorted array is:"<<endl;
for(intj=0;j<SIZE;j++)
cout<<setw(4)<<a[j];
return 0; // indicates successful termination
} // end main
// Function definition to sort the array
void selectionSort( int array[], int size )
{
int temp; // temporary variable used for swapping
// sort array until only one element is left
for(inti=0;<size-1;i++)
{temp=i;
for(int index=i+1;index<size;index++)
if(array[index]<array[temp])
temp=index;
swap(&array[i],&array[temp]);
}// end if statement
} // end method selectionSort
void swap(int*const element1ptr,int*const element2ptr)
{
int hold=*element1ptr;
*element1ptr=*element2ptr;
*element2ptr=hold;
}
The compiler doesn't know what you're trying to say at that point. The proper way is: int i = 0; (int i=0; is ok too - the important part is the space between the data type and the variable).
Line 31: cout<<set(4)<<[i]; -- set what? set width, set precision? Also, <<[i] - huh?
Line 42: cout<<setw(4)<<a[j]; -- what is a?
Fix those problems and you'll be in a good place to start really debugging your code.
Hint: There are (many) other problems, but those are a good starting point.