Jamblaster 15 Newbie Poster

Title says it all: I am wondering in what kind of situations a programmer would use a union vs using a structure. I'm pretty new to this stuff and my book only devotes about 2 pages to Unions so it isn't the best source of info on Unions really, but they look like they could be used to save a lot of RAM and I would like to know what kind of programs or functions they are intended for. Thanks, James.

Jamblaster 15 Newbie Poster

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.

Jamblaster 15 Newbie Poster

I am new to this site and also new to programming. I found this site through a google search looking for a solution to an error--> "no newline at end of file", but I figured out what I was doing wrong and saw that this is a wonderful site for community help with coding problems. My name is James and I am happy to be a member of Daniweb.

Jamblaster 15 Newbie Poster

When I read this the first thing that came to mind was---decision structures:

if()

else

Jamblaster 15 Newbie Poster

Ok I can't give you the answer, but here is what a programming instructor once told me:

"Inside the loop, you multiply the counter times the accumulated number up to that point (the accumulator has to be initialized to 1 before the loop). So if the user enters a 3--The first time through the loop, the counter is 1, so 1 * the accumulator 1 is 1. Second time through the loop, the counter is 2, so 2 * the accumulator 1 is 2. Third time through the loop, the counter is 3, so 3 * the accumulator 2 is 6. This is where the loop ends, and after the loop, 6 would be displayed as the answer."