SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 305 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 08 Jan 2018 My Price 10.00

supposed to sort the data according to the account

I need help with the following program. It is supposed to sort the data according to the account number. At the end it only sorts one column of information (account number) but the rest of the rows do not follow. 

You have to input 5 lines of data to reach the end of the program. The data input must resemble the following:

100 John 28.4 

233 Smith 37.9

3 Betty 18

18 Sam 89.9

400 Tom 57.9 

As you can see when it sorts the information at the end, its only the account number that changes. My instructor informed me to "swap the structure with the accountNumber." I'm not sure what he means. Attached is the program. 

Thanks for reading! 

/*----------------------------------------------------------
Program file:
Author:      
Date:         March 25, 2017
Assignment:   #5
Objective:    This program allows the user to to enter
        account data for a business.
------------------------------------------------------------*/
#include <stdio.h>


struct info
{
int accountNumber;
char lastName[30];
float accountBalance;
};


int main (void)
{

struct info client[5];
int     x, i, j;
int temp = 0;




printf("\n\nEnter account number, last name, and balance.\n");
printf("Enter -999 to end input.\n\n");


for (i = 0; i < 5; i++){

   do{
          printf("? ");
          scanf ("%i", &client[i].accountNumber);   
                if(client[i].accountNumber<1||client[i].accountNumber>1000)
                    printf ("**Invalid account number. Number must be between 1-1000, or -999 to exit**\n");
                if(client[i].accountNumber==-999){
                    printf("\n");
                    return 0;}    
      scanf("%29s", client[i].lastName);
      scanf("%f", &client[i].accountBalance);
                if(client[i].accountBalance<0)
                     printf ("**Invalid account balance. Please enter positive number.**\n");

  }while(client[i].accountNumber<1||client[i].accountNumber>1000||client[i].accountBalance<0);


} /* End for loop */

//Sorting Ascending Account Number

    for(i=0; i < 5 - 1; i++)
    {
         for(j = 0; j < 5 - i - 1; j++)
         {
             if(client[j].accountNumber>client[j+1].accountNumber)
             {
                  temp = client[j].accountNumber;
                  client[j].accountNumber = client[j+1].accountNumber;
                  client[j+1].accountNumber = temp;
               }
       }
  
}

printf("\n");
printf("%-15s %-15s %-15s\n","ACCOUNT","LAST NAME","BALANCE");

for(i = 0; (i < 5); i++){

printf("%-15d %-15s %-15.2f", client[i].accountNumber, client[i].lastName, client[i].accountBalance);
printf("\n");

}

printf("\n\n");

return 0;

 /* End main */}

Answers

(5)
Status NEW Posted 08 Jan 2018 02:01 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)