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

Define a 1-D array named people Types that can store a maximum of 50 integer val

ID: 3538079 • Letter: D

Question

Define a 1-D array named people Types that can store a maximum of 50 integer values that will be entered at the keyboard. enter a series of 1's, 2's, 3's, and 4's into the array, where one represents an infant, a 2 represents a child, a 3 represents a teenager, and a 4 represents an adult that was present. Any other integer value should not be accepted as a valid input, and data entry should stop when a negative value has been entered.

Your java program should count the number of each 1,2,3, and 4 in the array and output a list of how many infants, children, teenagers, and adults there were.

Explanation / Answer

[code] #include <stdio.h>

#define GUESTS 25


int main(int argc, const char * argv[])

{

int infant=0, child=0, teenager=0, adult=0;

int i;

int PeopleTypes [GUESTS];

  

  

printf("Please Enter the following 1 for a Infant: 2 for a Child: 3 for a Teenager: 4 for an Adult: ");

  

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


scanf("%d",&PeopleTypes [i]);

  

if (PeopleTypes[i] == 1) {

infant++;

}

if (PeopleTypes [i] == 2) {

child++;

}

if (PeopleTypes [i] == 3) {

teenager++;

}

if (PeopleTypes [i] == 4) {

adult++;

}

  

else if (PeopleTypes [i] > 5)

{

printf("(ERROR!!!) Please only enter a number 1-4.");

  

}

  

}

printf("There were %d Infants,%d Children,%d Teenagers, and %d Adults",infant,child,teenager,adult);

  

  

  

  

return 0;

  

}


[code]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote