|
|
|
|
Posted 2004-10-17, 03:52 PM
|
|
|
|
I need some help I wrote a program to count th number of people in each of the following groups: 0-16 infant, 16-29 young, 29-55 middle age, 55-75 old, 75- and older, really old. I have the program so that the user can input the ages but the part I do not know how to do is how to assign the numbers in a array to show me the aged group.
#inlcude <stdio.h>
main()
{
int age, group1=0, group2=0, group3=0, group4=0, group5=0;
printf ("Please enter an integer, when done enter -1\n");
scanf("%d", &age);
while (age>=0)
{
if (age<=16)
group1=group1+1;
else if (age<=29)
group2=group2+1;
else if (age<=55)
group3=group3+1;
else if (age<=75)
group4=group4+1;
else
group5=group5+1;
}
printf ("Please enter an integer, when done enter -1\n");
scanf("%d", &age);
printf("\n Results\n");
printf("In group age 0-16 we have individuals\n", group1);
printf("In group age 16-29 we have individuals\n", group2);
printf("In group age 29-55 we have individuals\n", group3);
printf("In group age 55-75 we have individuals\n", group4);
printf("In group age 75-old we have individuals\n", group5);
}
I am trying to assign these numbers in an array
4 17 79 52 56 19 21 22 3
12 30 33 81 99 85 28 24 25
24 26 27 20 44 32 35 24 39
43 41 46 56 62 22 20 69 18
|
|
|
|
|
|
|
|
|
|
|