6. Program that inputs age in years and display age in days and months.

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;
}

Code Screenshot:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

Output:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

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