Write a C++ program to read age of 15 people and count total Baby age, School age and Adult age.

Write a C++ program to read the age of 15 people and count total Baby age, School-age, and Adult age.

Write a C++ program to read age of 15 people and count total Baby age, School age and Adult age.

 

Object: Write a C++ program to read the age of 15 people and count total Baby age, School-age, and Adult age. C++ Projects.

Code:

#include<iostream>
#include<conio.h>

using namespace std;
void main()
{
int age, baby=0, school=0, adult=0, i=1;
while(i<=15)
{
cout<<“Enter age of Person “<<i<<” : “;
cin>>age;
if(age>=0 && age<=5)
{
baby++;
}
else if(age>=6 && age<=17)
{
school++;
}
else if(age>17)
{
adult++;
}
else
{
cout<<“Invalid!! Please Enter a valid age!!!.”<<endl;
}
i++;
}
cout<<“\nTotal Baby Ages is: “<<baby<<endl;
cout<<“Total School Ages is: “<<school<<endl;
cout<<“Total Adult Ages is: “<<adult<<endl;
getch();
}

#include<iostream>
#include<conio.h>

using namespace std;
void main()
{
	int age, baby=0, school=0, adult=0, i=1;
	while(i<=15)
	{
		cout<<"Enter age of Person "<<i<<" : ";
		cin>>age;
		if(age>=0 && age<=5)
		{
			baby++;
		}
		else if(age>=6 && age<=17)
		{
			school++;
		}
		else if(age>17)
		{
			adult++;
		}
		else
		{
			cout<<"Invalid!! Please Enter a valid age!!!."<<endl;
		}
		i++;
	}
	cout<<"\nTotal Baby Ages is: "<<baby<<endl;
	cout<<"Total School Ages is: "<<school<<endl;
	cout<<"Total Adult Ages is: "<<adult<<endl;
	getch();
}

Output:

Write a C++ program to read age of 15 people and count total Baby age, School age and Adult age.

Another Program: Write a program to swap two numbers using pointers.

1 thought on “Write a C++ program to read age of 15 people and count total Baby age, School age and Adult age.”

  1. It’s great that you are getting thoughts from this post as well as from our discussion made at this place.

Leave a Comment

Your email address will not be published. Required fields are marked *