I need it in descending order and also the ability to use decimals I tried to put double in everything but it wouldn't work it says that the array doesn't match with int. Help PLEASE!!!

#include <iostream.h>

void selectionSort(int *array,int length)//selection sort function 
{
	int i,j,min,minat;
	for(i=0;i<(length-1);i++)
	{
		minat=i;
		min=array[i];

      for(j=i+1;j<(length);j++) //select the min of the rest of array
	  {
		  if(min>array[j])   //ascending order for descending reverse
		  {
			  minat=j;  //the position of the min element 
			  min=array[j];
		  }
	  }
	  int temp=array[i] ;
	  array[i]=array[minat];  //swap 
	  array[minat]=temp;

		
	}

}



void printElements(int *array,int length) //print array elements
{
	int i=0;
	for(i=0;i<10;i++)
    cout<<array[i]<<endl;
}


void main()
{

	int a[]={9,6,5,23,2,6,2,7,1,8};   // array to sort 
    selectionSort(a,10);                 //call to selection sort  
	printElements(a,10);               // print elements 
}

never mind got it

actually i entered it and for some reason its not reconizing one of my decimal numbers i entered 2.5 and ti wouldn't come up the other ones did such as 7.7, 6.7, 8.5

so its not working need help again

so its not working need help again

Well your code has obviously changed since you last posted, so post the updated code with a description of the problem you now are having and the exact error message. Please post formatted code and use code tags.

[code]

// paste code here

[/code]

commented: Thanks for the help +1
Member Avatar for iamthwee
#include <iostream.h>

void selectionSort ( double *array, int length ) //selection sort function
{
  int i, j,minat;
  double min ;
  for ( i = 0; i < ( length - 1 ); i++ )
  {
    minat = i;
    min = array[i];

    for ( j = i + 1; j < ( length ); j++ ) //select the min of the rest of array
    {
      if ( min > array[j] ) //ascending order for descending reverse
      {
        minat = j; //the position of the min element
        min = array[j];
      }
    }
    double temp = array[i] ;
    array[i] = array[minat]; //swap
    array[minat] = temp; 
  }
} 

void printElements ( double *array, int length ) //print array elements
{
  int i = 0;
  for ( i = 0; i < 10; i++ )
    cout << array[i] << endl;
} 

void main()
{

  double a[] = {9, 6.4777, 5, 2.3, 2.8, 6, 2, 7, 1, 8}; // array to sort
  selectionSort ( a, 10 ); //call to selection sort
  printElements ( a, 10 ); // print elements
  
}

Maybe not tested properly...

ya i got the descending part

Member Avatar for iamthwee

Which part are you stuck on?

Hey thanks it worked out great

for some reason it was doing the other numbers as double but once the min was doubled it worked out great

Member Avatar for iamthwee

Mark this thread as solved then, and when you're finished school get a better compiler other than turbo c.

thank you and im using blodshed unfortunately its what this school is giving us well atleast in this class I usually use visual studios

Member Avatar for iamthwee

>im using blodshed

I doubt that. The latest version of bloodshed wouldn't have allowed you to compile and run it with void main, and possibly iostream.h.

And I use bloodshed dev-cpp.

sorry failed to put that part I just put the part that I was having problem with.

Member Avatar for iamthwee

So are you saying you compiled your original code with dev-cpp or visual studio?

And if so what version of visual studio are you using that would allow you get away with void main and iostream.h

no no I developed it in Dev-cpp but I like using visual studio's but I am not using it here.

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.