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.

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

1 Response

  1. Royal CBD says:

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

Leave a Reply

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