- #1
clook
- 35
- 0
the assignment wants me to count the number of people in age groups and to report the number of people in each group.
i came up with this, used an int for each group and incremented with if/else if statements.
though I'm not sure if its exactly right.. and it won't let me compile.
i keep getting the "unexpected end of file" error. please help? :)i also want to make it so that you can enter as many ages as you want, but I'm not sure what kind of loop i should use for that.
i came up with this, used an int for each group and incremented with if/else if statements.
Code:
#include<stdio.h>
main()
{
int x, infant, young, middleaged, old, older, reallyold;
infant = 0;
young = 0;
middleaged = 0;
old = 0;
older = 0;
reallyold = 0;
printf("Please enter ages (Enter -1 to quit): ");
scanf("%d", x);
while (x != -1)
{
if (x <= 16)
infant++;
else if (x <= 29)
young++;
else if (x <= 55)
middleaged++;
else if (x <= 75)
old++;
else if (x <= 99)
older++;
else if (x > 99)
reallyold++;
printf("Number of infants: %d \n", infant);
printf("Number of young people: %d \n", young);
printf("Number of middle aged people: %d \n", middleaged);
printf("Number of old people: %d \n", old);
printf("Number of older people: %d \n", older);
printf("Number of really old people: %d \n", reallyold);}
though I'm not sure if its exactly right.. and it won't let me compile.
i keep getting the "unexpected end of file" error. please help? :)i also want to make it so that you can enter as many ages as you want, but I'm not sure what kind of loop i should use for that.
Last edited: