The cin Object in C++ - Example program 02
Write a C++ program to get name and age (in years) of a persons. Calculate age in months and days and print the name of the person and its age in months and days.
Sample Output:
Enter name of Person : Kashif
Enter age of Person (in years) : 28
-------------------------------------------------
Name of Person : Kashif
Age is Years : 28 Years
Age in Months : 336 Months
Age in Days : 10080 Days
------------------------------------------------
We can write this program. See complete program with output. It is given below:
Program CODE:
#include<iostream.h>
#include<conio.h>
main(){
int age_years, age_months, age_days;
char name[15];
clrscr();
cout<<"Enter name of Person : ";
cin>>name;
cout<<"Enter age of Person (in years) : ";
cin>>age_years;
age_months = age_years*12;
age_days = age_months*30;
cout<<"---------------------------"<<endl;
cout<<"Name of Person : "<<name<<endl;
cout<<"Age is Years : "<<age_years<<endl;
cout<<"Age is Months : "<<age_months<<endl;
cout<<"Age is Days : "<<age_days<<endl;
cout<<"---------------------------"<<endl;
}
#include<conio.h>
main(){
int age_years, age_months, age_days;
char name[15];
clrscr();
cout<<"Enter name of Person : ";
cin>>name;
cout<<"Enter age of Person (in years) : ";
cin>>age_years;
age_months = age_years*12;
age_days = age_months*30;
cout<<"---------------------------"<<endl;
cout<<"Name of Person : "<<name<<endl;
cout<<"Age is Years : "<<age_years<<endl;
cout<<"Age is Months : "<<age_months<<endl;
cout<<"Age is Days : "<<age_days<<endl;
cout<<"---------------------------"<<endl;
}
NEXT Lecture
0 comments:
Post a Comment