Chapter 4:
Input And Output
Programming Exercise
Problem # 6:
Write a program that inputs age in years and display age in days and months.
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int ageInYears, ageInDays, ageInMonths;
cout<<"Enter your age in years: ";
cin>>ageInYears;
ageInMonths = ageInYears*12;
cout<<"Your age in months: "<<ageInMonths<<endl;
ageInDays = ageInYears*365;
cout<<"Your age in days :"<<ageInDays<<endl;
return 0;
}
#include<conio.h>
using namespace std;
int main()
{
int ageInYears, ageInDays, ageInMonths;
cout<<"Enter your age in years: ";
cin>>ageInYears;
ageInMonths = ageInYears*12;
cout<<"Your age in months: "<<ageInMonths<<endl;
ageInDays = ageInYears*365;
cout<<"Your age in days :"<<ageInDays<<endl;
return 0;
}
Code Screenshot:
Output:
Let me know in the comment section if you have any question.
Previous Post:
5. Program that inputs miles from the user and convert miles into kilometers.
Comments
Post a Comment