Modify your struct person to include an additional field to hold a last name. That should be declared as char lname[30]; //30 characters is probably long enough Modify your program so that in addition to reading ages and heights, it reads in a name for each person. At the end, in addition to printing the averages calculated previously, print the names of the oldest, youngest, tallest, and shortest people.

Respuesta :

Answer:

The answer to the question is explained below

Explanation:

#include <stdlib.h>

#include <stdio.h>

#define MAXNUM 100

typedef struct person

{

int age;

double height;

}

person;

int getData(person people[], int max)

{

printf("Enter your age(or -1 to quit):");

int n = 0;

scanf("%d", &people[n].age);

while (people[n].age>0)

{

   if(n == MAXNUM)

   {

     printf("You have reached the maximum limit");

     return n;

   }

   printf("Enter your height:");

scanf("%lf", &people[n++].height);

printf("Enter your age(or -1 to quit):");

scanf("%d", &people[n].age);

}

    return n;

}

void getAverages(person people[], double *averageAge, double * averageHeight, double *averageRatio, int numPeople)

{

*averageAge = 0;

*averageHeight = 0;

for(int i = 0; i <numPeople; i++)

{

   *averageAge += people[i].age;

   *averageHeight += people[i].height;

}

   *averageAge /= numPeople;

   *averageHeight /= numPeople;

   *averageRatio = *averageAge / *averageHeight;    

}

void printAverages(double averageAge, double averageHeight, double averageRatio)

{

int age;

double height;

printf("Result:\n");

printf("Average age is %.2lf\n", averageAge);

printf("Average height is %.2lf\n", averageHeight);

printf("The average age/height ratio is %.2lf\n", averageRatio);  

}

void main(void)

{

person people[MAXNUM];

int numPeople;

double averageAge, averageHeight, averageRatio;

numPeople = getData(people, MAXNUM);

if (numPeople == 0);

getAverages(people, &averageAge, &averageHeight, &averageRatio, numPeople);

printAverages(averageAge, averageHeight, averageRatio);

}