First off let me say that I am a student and do not want any answers. What I do want is some help understanding why my logic isn't working so I can devise a new plan. Any help at all would be greatly appreciated because I am completely stuck atm and would like to get unstuck. Thanks, James.

/* Function definition--ascending */
void ascending() {
  int x = 0;
  int temp = 0;
  float fUserArray[10] = {0};
    
  for(x=0; x<10; x++) {
  printf("\nPlease enter a number:  ");
  scanf("%f", &fUserArray[x]);
  }//end for loop
    for(x=0;x<10; x++) {
      if(fUserArray[x] > fUserArray[x+1]) {
      temp = fUserArray[x];
	  fUserArray[x] = fUserArray[x+1];
	  fUserArray[x+1] = temp;
      }//end if
	}//end for loop
	printf("\nYour numbers in ascending order are:");
	for(x=0;x<10;x++){
	  printf("\n%.2f", fUserArray[x]); }//end for
	}//End ascending function
	
	/**********************************/
	
	
/*Function definition--descending */

  void descending() {

  int x = 0;
  int temp = 0;
  float fUserArray[10] = {0};
      
  for(x=0;x<10;x++) {
    printf("\nPlease enter a number:  ");
    scanf("%f", &fUserArray[x]); 
	}//end for loop
	for(x=0;x<10;x++) {
	    if(fUserArray[x] < fUserArray[x+1]){
		temp = fUserArray[x];
	    fUserArray[x] = fUserArray[x+1];
	    fUserArray[x+1] = temp;
	    }//end if 
      }//End for loop
	printf("\nYour numbers in descending order are:");
	for(x=0;x<10;x++)  {
	  printf("\n%.2f", fUserArray[x]);
	}//end for loop
	}//end descending function
	
	/**********************************/

Like I already stated--> I can't figure out why the array isn't sorting and would like some help understanding where my logic is faulty thanks.

Welcome to the forum, Jamblaster! ;)

Always click on the [code ] icon and when it puts two code tags on your reply page, paste your code, between the code tags - easy to do since it puts your cursor right between them for you.

All comparison sorts except for 1 obscure one, require two loops - one nested inside the other. You are sorting one pass OK, but that is just one pass, not everything.

This is the pseudo code for a simple substitution sort (like a bubble sort, but a bit quicker/easier, and no bubbles. (not always quicker, but usually).

int temp

for(i...;; i++) {
  for(j=i+1;...; j++) {
     if(array[i] > array[j]) {
        do your swap of array[i] and array[j], and use a temp variable
     }
  }
}

/* Function definition--ascending */

for(x=0;x<10; x++) 
for(y=x+1;y<=10; y++) 
{
if(fUserArray[x] > fUserArray[y]) {
temp = fUserArray[x];
fUserArray[x] = fUserArray[y];
fUserArray[y] = temp;
}//end if
}//end for loop

For sorting a list of one dimention you will need two for loops.

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.