Question: I have to write a program in C that states the following: Description: using a while loop Ask for ages until a negative value is

I have to write a program in C that states the following:

Description: using a while loop

Ask for ages until a negative value is entered

When complete report the following

How many ages were entered ( not counting the signal at end )

How many are minors, under 18

How many could be retired, 65 or older

This is what I have so far:

#include

int main()

{ int age, retired = 0, minors = 0, total = 0; while(age>=0) { printf("Enter age of person: "); scanf("%d",&age); if(age>=65&&age<=100) retired++; if(age>=0&&age<18) minors++; }

total++; printf("%d", total); printf(" number of ages: ");

age++; printf("%d", minors); printf(" number of minors: ");

printf("%d", retired); printf(" number of retirees: ");

return 0;

}

This is what it looks like when I compile it:

Enter age of person: 15 Enter age of person: 74 Enter age of person: 23 Enter age of person: 43 Enter age of person: -1 1 number of ages: 1 number of minors: 1 number of retirees:

I can't figure out what I'm doing wrong to get it to print correctly. Any help is greatly appreciated.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!