Write a C++ program to read the 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:
Another Program: Write a program to swap two numbers using pointers.
It’s great that you are getting thoughts from this post as well as from our discussion made at this place.