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

hello I need help my program doesn\'t seem to work thank you You are to create a

ID: 3595828 • Letter: H

Question

hello

I need help my program doesn't seem to work

thank you

You are to create a C program with the following menu:

[A]dd a new client

[D]isplay all clients

[I]ncome Average for all clients

[Q]uit

A client has the following information:

Name (First, Middle Initial, Last Name)

First name and Last Name first letter Caps and others lowercase

Middle Initial is Uppercase

Date of Birth

All Rules with Dates

Annual Income

Gender

The program will store between 0 and 1000 clients.

You are to create at least 3 structs. You are to create functions for handling names, and dates. Your functions should be used to set a value for these data types and to retrieve values from these data types.

Your code should be well documented. All your work will be done in functions outside of main. Your code will be well documented and you will include a design tool. You need to do this assignment on your own. No need for groups.

Optional (add the following for some type of extra credit if you wish)

Sort by Name

Sort by Income

Delete a client

Edit a client

#define _CRT_SECURE_NO_WARINGS

#define PAUSE system("pause")

#define FLUSH myFlush()

#define CLS system("cls")

#define SIZE 1000

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

// Structs

typedef struct{

char firstName [50];

char middleI;

char lastName[74];

}NAME;

typedef struct{

int month;

int day;

int year;

}DATE;

typedef struct{

NAME name;

DATE dob;

float income;

char gender;

}CLIENTS;

// Protype Function

void addClient(CLIENTS clients[], int *counter);

void annualPay(CLIENTS *income);

void birthday(DATE *dob);

void getName(NAME *name);

void gender(CLIENTS *gender);

void displayAll(CLIENTS client[], int *counter);

void incomeavg(CLIENTS client[], int);

void myFlush(void);

void displayMenu(void);

char getChoice(void);

int main() {

CLIENTS clients[SIZE];

int counter = 0;

char choice;

choice = getChoice();

  

  

do{

switch(choice){

case 'A':// add a client info

addClient(clients, &counter);

PAUSE;

break;

case 'D':

PAUSE;

break;

case 'I':

incomeavg(clients, counter);

PAUSE;

break;

case 'Q':

printf("GoodBye ");

break;

default:

printf("Invaild selection ");

PAUSE;

break;

}// end switch

}while(choice != 'Q');

}// end main

void addClient(CLIENTS clients[], int *counter){

int i;

printf(" How may Clients would you Like to Enter: ");

scanf("%i", counter);

for (i = 0; i < *counter; i++){

getName(&clients[*counter].name);

birthday(&clients[*counter].dob);

annualPay(clients);

gender(clients);

}// end for loop

}//end addClients

void annualPay(CLIENTS *income){

printf("Enter Annual income: ");

scanf("%f", &income->income);

FLUSH;

}// end annualPay

void birthday(DATE *dob){

char invaild ='Y';

  

printf("DATE of Birth ");

printf("Enter the Month: ");

scanf("%i", &dob->month);

FLUSH;

printf("Enter the Day: ");

scanf("%i", &dob->day);

FLUSH;

printf("Enter the Year: ");

scanf("%i", &dob->year);

FLUSH;

// validate date

if (dob -> month >12 || dob -> month <1){

printf(" Invaild month between 1 and 12 ");

invaild = 'Y';

}//end if

if( dob -> year <1000 || dob -> year > 9999 ){

printf("invaild year beteen 1000 and 9999 only");

invaild ='Y';

}// end if

switch(dob -> month){

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

if(dob -> day < 1 || dob -> day > 31){

printf("INVAILD DATE BETWEEN 1 AND 31");

PAUSE;

invaild = 'Y';

}//end if

break;

  

case 4:

case 6:

case 9:

case 11:

if(dob -> day < 1 || dob -> day > 31){

printf("INVAILD DATE BETWEEN 1 AND 31");

PAUSE;

invaild = 'Y';

}//end if

break;

case 2:

if ((dob -> year % 4 !=0 && dob -> day < 1)|| dob -> day > 29){

printf("Invaild day between 1 and 29 only");

PAUSE;

invaild = 'Y';

}// end if

  

}// ENd swicth

  

}// End birthday

void displayMenu(){

printf("[A]dd a new client ");

printf("[D]isplay all clients ");

printf("[I]ncome average for clients ");

printf("[Q]uit ");

printf("Enter your choice: ");

}// end displaymenu

void display(CLIENTS client[], int * counter){

  

int i;

printf(" Full Name, DOB, Annual Income, Gender");

for (i = 0; i < *counter; i++){

printf("%s %s %f %c ", client->name,client->dob, client->income,client->gender);

   }

}

char getChoice(){

char result;

displayMenu();

scanf("%c", &result);

FLUSH;

return toupper(result);

}// END getChoice()

void getName(NAME *name){

printf("Enter your first name: ");

scanf("%s", &name->firstName);

FLUSH;

printf("Enter middle initial: ");

scanf("%c", &name->middleI);

FLUSH;

printf("Enter Your Last Name: ");

scanf("%s",&name->lastName);

FLUSH;

//fix upper the name here

}// end getName

void gender(CLIENTS *gender){

printf(" What is your Gender (M)ale or (F)emale: ");

scanf("%c", &gender->gender);

FLUSH;

}// END GENDER

void incomeavg(CLIENTS client[], int c){

int i, avg=0;

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

avg=avg+client->income;

  

}

}// end income avg

void myFlush(){

while(getchar() != ' ');

} // end myFlush()

Explanation / Answer

#define _CRT_SECURE_NO_WARINGS
#define PAUSE system("pause")
#define FLUSH myFlush()
#define CLS system("cls")
#define SIZE 1000

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

// Structure name definition
typedef struct
{
//To store name
char firstName [50];
char middleI;
char lastName[74];
}NAME;
// Structure date of birth definition
typedef struct
{
//To store date of birth
int month;
int day;
int year;
}DATE;
// Structure client definition
typedef struct
{
//To store client information
NAME name;
DATE dob;
float income;
char gender;
}CLIENTS;

// Prototype Function
void addClient(CLIENTS clients[], int *counter);
void annualPay(CLIENTS *income);
void birthday(DATE *dob);
void getName(CLIENTS *name);
void gender(CLIENTS *gender);
void displayClients(CLIENTS client[], int counter);
void incomeavg(CLIENTS client[], int);
void myFlush(void);
void displayMenu(void);
void sortByName(CLIENTS client[], int counter);
void sortByIncome(CLIENTS client[], int counter);
char getChoice(void);
//Main method definition
int main()
{
//Creates an array of client objects
CLIENTS clients[SIZE];
//To store record counter
int counter = 0;
//To store choice
char choice;
//To store sorting choice
int ch;
//Loops till user choice is not 'Q'
do
{
//Displays menu and stores user choice
choice = getChoice();
//Checks choice and calls appropriate function
switch(choice)
{
// Add a client information
case 'A':
addClient(clients, &counter);
PAUSE;
break;
//Display client information
case 'D':
displayClients(clients, counter);
PAUSE;
break;
//Displays income average
case 'I':
incomeavg(clients, counter);
PAUSE;
break;
//Sorting
case 'S':
//Displays sub menu and accepts user choice
printf(" 1 for sort by Name 2 for sort by Income: ");
scanf("%d", &ch);
FLUSH;
//Checks user choice
switch(ch)
{
//Sort by first name
case 1:
sortByName(clients, counter);
displayClients(clients, counter);
break;
//Sort by income
case 2:
sortByIncome(clients, counter);
displayClients(clients, counter);
break;
default:
printf(" ERROR: Invalid choice!");
}//End of switch
break;
case 'Q':
printf("GoodBye ");
break;
default:
printf(" Error: Invalid selection ");
PAUSE;
break;
}// end switch
}while(choice != 'Q');
}// end main
//Function to sort by income
void sortByIncome(CLIENTS clinets[], int no)
{
int x, y;
//Creates a temporary object
CLIENTS temp;
//Loops till length of the array
for(x = 0; x < no; x++)
{
//Loops till length of the array minus x minus one times
for(y = 0; y < no - x - 1; y++)
{
//Checks if current index position of the array is greater than the next index position of the array
if(clinets[y].income > clinets[y+1].income)
{
//Swapping process
temp = clinets[y];
clinets[y] = clinets[y + 1];
clinets[y + 1] = temp;
}//End of if condition
}//End of inner for loop
}//End of outer for loop
}//End of function
//Function to sort by first name
void sortByName(CLIENTS clinets[], int no)
{
int x, y;
//Creates a temporary object
CLIENTS temp;
//Loops till length of the array
for(x = 0; x < no; x++)
{
//Loops till length of the array minus x minus one times
for(y = 0; y < no - x - 1; y++)
{
//Checks if current index position of the array is greater than the next index position of the array
if(strcmp(clinets[y].name.firstName, clinets[y+1].name.firstName) > 0)
{
//Swapping process
temp = clinets[y];
clinets[y] = clinets[y + 1];
clinets[y + 1] = temp;
}//End of if condition
}//End of inner for loop
}//End of outer for loop
}//End of function
//Function to add a client information
void addClient(CLIENTS clients[], int *counter)
{
int i;
int c;
//Accepts number of clients
printf(" How may Clients would you Like to Enter: ");
scanf("%d", &c);
//Loops till number of clients
for (i = *counter; i < (*counter+c); i++)
{
//Accepts data by calling functions
getName(&clients[i]);
birthday(&clients[i].dob);
annualPay(&clients[i]);
gender(&clients[i]);
}// end for loop
//Adds current counter with record counter
*counter += c;
}//end addClients

//Function to accept name
void getName(CLIENTS *client)
{
char name[50];
printf(" Enter your first name: ");
scanf("%s", name);
//Converts first letter to upper case
name[0] = toupper(name[0]);
strcpy(client->name.firstName, name);
FLUSH;
printf(" Enter middle initial: ");
scanf("%c", &client->name.middleI);
//Convert to upper case
toupper(client->name.middleI);
FLUSH;
printf(" Enter Your Last Name: ");
scanf("%s", name);
//Converts first letter to upper case
name[0] = toupper(name[0]);
strcpy(client->name.lastName, name);
FLUSH;
}// end getName
//Function to accept annual income
void annualPay(CLIENTS *income)
{
printf(" Enter Annual income: ");
scanf("%f", &income->income);
FLUSH;
}// end annualPay
//Function to accept DOB
void birthday(DATE *dob)
{
char invaild;
//Loops till valid date of birth
do
{
invaild = 'N';
printf(" DATE of Birth");
printf(" Enter the Month: ");
scanf("%i", &dob->month);
FLUSH;
printf(" Enter the Day: ");
scanf("%i", &dob->day);
FLUSH;
printf(" Enter the Year: ");
scanf("%i", &dob->year);

FLUSH;
// validate date
if (dob -> month >12 || dob -> month <1)
{
printf(" Error: Invalid month between 1 and 12");
invaild = 'Y';
}//end if
if( dob -> year <1000 || dob -> year > 9999 )
{
printf(" Error: Invalid year between 1000 and 9999 only");
invaild ='Y';
}// end if
switch(dob -> month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(dob -> day < 1 || dob -> day > 31)
{
printf(" Error: INVAILD DATE BETWEEN 1 AND 31");
invaild = 'Y';
}//end if
break;

case 4:
case 6:
case 9:
case 11:
if(dob -> day < 1 || dob -> day > 31)
{
printf(" Error: INVAILD DATE BETWEEN 1 AND 31");
invaild = 'Y';
}//end if
break;
case 2:
if ((dob -> year % 4 !=0 && dob -> day < 1)|| dob -> day > 29)
{
printf(" Error: Invalid day between 1 and 29 only");
invaild = 'Y';
}// end if
}// ENd switch
}while(invaild == 'Y');
}// End birthday

//Function to display menu
void displayMenu()
{
printf("[A]dd a new client ");
printf("[D]isplay all clients ");
printf("[I]ncome average for clients ");
printf("[S]ort ");
printf("[Q]uit");
printf(" Enter your choice: ");
}// end display menu
//Function to display client information
void displayClients(CLIENTS clients[], int counter)
{

int i;
//Displays heading
printf(" %-31s %-15s %-9s %-15s ", "Full Name","DOB", "Gender", "Annual Income ");
//Loops till end of record counter
for (i = 0; i < counter; i++)
{
printf(" %-13s %-2c %-12s", clients[i].name.firstName, clients[i].name.middleI, clients[i].name.lastName);
printf(" %2d/%2d/%4d", clients[i].dob.day, clients[i].dob.month, clients[i].dob.year);
printf(" %6c", clients[i].gender);
printf(" %14.2f", clients[i].income);
printf(" ");
}//End of for loop
}//End of display function
//Accepts user choice
char getChoice()
{
char result;
displayMenu();
FLUSH;
scanf("%c", &result);
return toupper(result);
}// END getChoice()
//Accepts gender
void gender(CLIENTS *gender)
{
printf(" What is your Gender (M)ale or (F)emale: ");
scanf("%c", &gender->gender);
FLUSH;
}// END GENDER
//Calculates average income
void incomeavg(CLIENTS client[], int c)
{
int i;
float tot = 0, avg;
for (i = 0; i < c; i++)
tot += client[i].income;
avg = tot / c;
printf(" Average income of clients: %.2f", avg);
}// end income avg
//Flushes standard input device
void myFlush()
{
//while(getchar() != ' ');
fflush(stdin);
} // end myFlush()

Sample Run:

[A]dd a new client
[D]isplay all clients
[I]ncome average for clients
[S]ort
[Q]uit
Enter your choice: a

How may Clients would you Like to Enter: 2

Enter your first name: sasmita

Enter middle initial: k

Enter Your Last Name: panda

DATE of Birth
Enter the Month: 10

Enter the Day: 22

Enter the Year: 2013

Enter Annual income: 1000

What is your Gender (M)ale or (F)emale: f

Enter your first name: pyari

Enter middle initial: m

Enter Your Last Name: sahu

DATE of Birth
Enter the Month: 3

Enter the Day: 12

Enter the Year: 2015

Enter Annual income: 2000

What is your Gender (M)ale or (F)emale: m
Press any key to continue . . .
[A]dd a new client
[D]isplay all clients
[I]ncome average for clients
[S]ort
[Q]uit
Enter your choice: d

Full Name DOB Gender Annual Income
Sasmita k Panda 22/10/2013 f 1000.00
Pyari m Sahu 12/ 3/2015 m 2000.00
Press any key to continue . . .
[A]dd a new client
[D]isplay all clients
[I]ncome average for clients
[S]ort
[Q]uit
Enter your choice: i

Average income of clients: 1500.00Press any key to continue . . .
[A]dd a new client
[D]isplay all clients
[I]ncome average for clients
[S]ort
[Q]uit
Enter your choice: s

1 for sort by Name
2 for sort by Income: 1

Full Name DOB Gender Annual Income
Pyari m Sahu 12/ 3/2015 m 2000.00
Sasmita k Panda 22/10/2013 f 1000.00
[A]dd a new client
[D]isplay all clients
[I]ncome average for clients
[S]ort
[Q]uit
Enter your choice: s

1 for sort by Name
2 for sort by Income: 2

Full Name DOB Gender Annual Income
Sasmita k Panda 22/10/2013 f 1000.00
Pyari m Sahu 12/ 3/2015 m 2000.00
[A]dd a new client
[D]isplay all clients
[I]ncome average for clients
[S]ort
[Q]uit
Enter your choice: q
GoodBye