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

Need help with - Design a program that will allow a user to input a list of your

ID: 3639957 • Letter: N

Question

Need help with - Design a program that will allow a user to input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Iowa. You may assume that there are no more than 100 living relatives in your family. Each of these items (sequential code, at least one selection statement, at least one loop, at least one function call, at least one array and associated processing of the array) is required, and must be present in your code.

Explanation / Answer

Since no language was written above in which to write the program, I assumed it to be C++

#include<iostream>
#include<cstring>    //for strcmp()
#include<cstdio>     //for fflush()
using namespace std;
int familyavg(int [],int);
int main()
{
    char familyplace[100][100],familyname[100][100];
    int a,i,avg,familyage[100];
    cout<<"Enter the number of family members: ";
    cin>>a;
    fflush(stdin);
    for(i=0;i<a;i++)
    {
        cout<<"Enter family member name: ";
        cin.getline(familyname[i],100);
        cout<<"Enter family member age: ";
        cin>>familyage[i];
        fflush(stdin);   /* It is necessary otherwise there is problem with taking the next input(it clears the input buffer*/
        cout<<"Enter family member place: ";
        cin.getline(familyplace[i],100);
    }
    avg= familyavg(familyage,a);
    cout<<" The average age of the family is: "<<avg;
    cout<<" The family members living in Iowa are: ";
    for(i=0;i<a;i++)
    {
        if(strcmp(familyplace[i],"Iowa")==0 || strcmp(familyplace[i],"iowa")==0) cout<<" "<<familyname[i];
    }
    return 0;
}
int familyavg(int t[100],int b)
{
    int i,s=0;
    for(i=0;i<b;i++)
    {
        s = s+t[i];
    }
    s = s/b;
    return s;
}