hello, i cant get the expected output. below is my code #include typedef struct { int age; char gender; } Person; void displayPerson(Person); int main(void) { Person persons[5]; for(int i=0;i


hello, i cant get the expected output. below is my code


#include
typedef struct
{
    int age;
    char gender;
} Person;


void displayPerson(Person);


int main(void)
{
    Person persons[5];
    for(int i=0;i<>
    {
        printf("Person #%d\n",i+1);
        printf("Enter Person's age: ");
        scanf("%d",&persons[i].age);
        printf("Enter Person's gender: ");
        scanf("%c",&persons[i].gender);

    }
    for(int i=0;i<>
        displayPerson(persons[i]);


    return 0;
}


void displayPerson(Person p)
{
    printf("PERSON DETAILS:\n");
    printf("Age: %d\n", p.age);
    printf("Gender: ");
    if(p.gender == 'M')
    {
        printf("Male");
    }
    else
    {
        printf("Female");
    }
}







Instructions:



  1. In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age and character value for its gender. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter. In the main() function, there's a pre-created array of 5 Persons.

  2. Your task is to ask the user for the values of the age and gender of these Persons.

  3. Then, once you've set their ages and genders, call the displayPerson() function and pass them one by one.






Input




1. A series of ages and genders of the 5 Persons





Input<br>1. A series of ages and genders of the 5 Persons<br>Cutput<br>Person #1<br>Enter Person's age: 24<br>Enter Person's gender: M<br>Person #2<br>Enter Person's age: 21<br>Enter Person's gender: F<br>Person a<br>Enter Person's age: 22<br>Enter Person's gender: F<br>Person 4<br>Enter Person's age: he<br>Enter Person's gender: F<br>Person 5<br>Enter Person's age: 54<br>Enter Person's gender: M<br>PERSON DETAILS:<br>Age: 24<br>Gender: Male<br>PERSON DETALS:<br>Age 21<br>Gender: Fenale<br>PERSON DETALLS:<br>Age: 22<br>Gender: Fenale<br>PERSON DETALS:<br>Age: 60<br>Gender: Fenale<br>PERSON DETALSI<br>Age: 64<br>Gender: Male<br>

Extracted text: Input 1. A series of ages and genders of the 5 Persons Cutput Person #1 Enter Person's age: 24 Enter Person's gender: M Person #2 Enter Person's age: 21 Enter Person's gender: F Person a Enter Person's age: 22 Enter Person's gender: F Person 4 Enter Person's age: he Enter Person's gender: F Person 5 Enter Person's age: 54 Enter Person's gender: M PERSON DETAILS: Age: 24 Gender: Male PERSON DETALS: Age 21 Gender: Fenale PERSON DETALLS: Age: 22 Gender: Fenale PERSON DETALS: Age: 60 Gender: Fenale PERSON DETALSI Age: 64 Gender: Male
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here