Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am not sure Im doing it right Write a C program that prompts the user to enter

ID: 3641068 • Letter: I

Question

I am not sure Im doing it right

Write a C program that prompts the user to enter some data regarding some clients. The user should prompt for client account number (a UNIQUE positive integer between 1 and 1000), a name (a string, up to 25 in length), and the account balance (a positive floating point number) as shown below. The user input terminates once the user enters a -999 as the account number. I will let you decide the appropriate prompts and edit messages.

You should store this information in an array of type struct (something).
Make the array sizes large enough to hold data for up to 25 clients.

Once the user has completed entering the data, the program should then SORT THE DATA IN ASCENDING ORDER BY ACCOUNT NUMBER, OR NAME OR BALANCE, and output the client data in table form of your design or exactly as follows BELOW.

If the user enters -999 as the first account number, the program should simply exit, and display an appropriate message of your choice.
The report will also be directed to an output text file with the same output as printed to the screen. Sample I-O below – user responses are in coral:

Welcome to Client Center


Enter Client Number (1-1000; -999 to end): 123

Enter full name for client number 123: Doe, John

Enter Balance amount for employee Doe, John: 1022

Enter Client Number (1-1000; -999 to end): 233

Enter full name for client number 233: Doe, Jane

Enter Balance amount for employee Doe, Jane: 4443

Enter Client Number (1-1000; -999 to end): 543

Enter full name for client number 543: Smith, Ron

Enter Balance amount for employee Smith, Ron: 1102

Enter Client Number (1-1000; -999 to end): 123
Client number entered has already been used, re-enter.


Enter Client Number (1-1000; -999 to end): 129

Enter full name for client number 129: Smythe, Bill

Enter Balance amount for employee Smythe, Bill: 5555

Enter Client Number (1-1000; -999 to end): -999

4 clients

Sort by: Client Number(N), Name(A) or Balance (B): n



Client Number Client Name Balance


0123 Doe, John 1022.00

0129 Smythe, Bill 5555.00

0233 Doe, Jane 4443.00

0543 Smith, Ron 1102.00


(Report has been sent to report5.txt also)

Here is what I have so far:

#include<stdio.h>


struct info
{
int account[4];
char name[25];
float account_balance[10];
};
main()
{
struct info client[25];
int x = 0, i, num;


printf("Welcome to Client Center ");

for(x =0 ; x <= 25 ;x++)
{
printf("Enter Client Number(1-1000; -999 to end): ");
scanf("%i", &client[x]. account);
fflush(stdin);

if(client[i].account == -999)

{
printf(" Client number must be between 1 and 1000, re-enter ");
printf("Enter Client Number(1 - 100; -999 to end): ");

}

printf("Enter full name for client number %i: ", client[x].account);
gets(client[i]. name);

printf("Enter Balance amount for employee %s: ", client[x]. name);
gets(client[i].account_balance);

}



}

Explanation / Answer

please rate - thanks

#include<stdio.h>

#include <conio.h>
struct info
{
int account;
char name[25];
float account_balance;
};
int main()
{
struct info client[25],temp;
int x = 0, i,j, num,error;
char choice;
FILE *output;
   output = fopen("report5.txt","w");
                       
printf("Welcome to Client Center ");
printf("Enter Client Number(1-1000; -999 to end): ");
scanf("%i", &client[x].account);
fflush(stdin);
while(client[x].account!=-999)
   {error=0;
    while(client[x].account<1||client[x].account>1000)
           {printf(" Client number must be between 1 and 1000, re-enter ");
            x--;
            error=1;
            }
    for(i=0;i<x;i++)
         if(client[x].account==client[i].account)
             {x--;
             error=1;
             printf("Client number entered has already been used, re-enter. ");
             break;
             }
   
if(error==0)
    {printf("Enter full name for client number %i: ", client[x].account);
    gets(client[i]. name);

    printf("Enter Balance amount for employee %s: ", client[x]. name);
    scanf("%f",&client[i].account_balance);
   
    }
    x++;
    printf("Enter Client Number(1 - 1000; -999 to end): ");
    scanf("%i", &client[x].account);
    fflush(stdin);
}
if(x==0)
    printf("no clients-program exiting ");
else
{
printf("%d clients ",x);
printf("Sort by: Client Number(N), Name(A) or Balance (B): ");
scanf("%c",&choice);
choice=toupper(choice);
if(choice=='N')
    {for(i=0;i<x-1;i++)
         for(j=i+1;j<x;j++)
             if(client[i].account>client[j].account)
                  {temp=client[i];
                  client[i]=client[j];
                  client[j]=temp;
               }
}
else if(choice=='A')
    {for(i=0;i<x-1;i++)
         for(j=i+1;j<x;j++)
             if(strcmp(client[i].name,client[j].name)>0)
                  {temp=client[i];
                  client[i]=client[j];
                  client[j]=temp;
                  }
}
else if(choice=='B')
{for(i=0;i<x-1;i++)
         for(j=i+1;j<x;j++)
             if(client[i].account_balance>client[j].account_balance)
                  {temp=client[i];
                  client[i]=client[j];
                  client[j]=temp;
                  }
}
else
     printf("Invalid entry-no sort will be done ");
    
printf("Client Number Client Name Balance ");
fprintf(output,"Client Number Client Name Balance ");
for(i=0;i<x;i++)
   {printf("%4d %s   %6.2f ",client[i].account,client[i].name,client[i].account_balance);
   fprintf(output,"%4d %s   %6.2f ",client[i].account,client[i].name,client[i].account_balance);

}
}
printf(" (Report has been sent to report5.txt also) ");

fclose(output);
getch();
return 0;

}