Why is it that when I run this, I it will ask for the name the first time but when it loops around it will skip asking for name and go straight to asking for the account number??
I just cant seem to get it to work. Also my bubble sort will not sort the names, only acct # and the balance. Please help!
Code:struct info{char name[30]; int account_num; float balance; }; struct info people[25]; int x,a,y,temp=0; //loop to collect info*/ for(x = 1; x <= 3; ++x) { printf("Enter Name: "); gets(people[x].name); printf("Enter Account Number: "); scanf("%i",&people[x].account_num); printf("Enter Balance: "); scanf("%f",&people[x].balance); printf("\n"); } //bubble sort for (a=1; a<x-1;++a) { for (x=1; x<3;++x) { if (people[x].account_num>people[x+1].account_num) { temp = people[x+1].account_num; people[x+1].account_num = people[x].account_num; people[x].account_num = temp; temp2 = people[x+1].name[30]; people[x+1].name[30] = people[x].name[30]; people[x].name[30] = temp2; temp = people[x].balance; people[x].balance = people[x+1].balance; people[x+1].balance = temp; }/*end if*/ }/*end nested for*/ }/*end for loop*/ char temp2=0;



LinkBack URL
About LinkBacks



