Write a program which accept days as integer and display total number of years,months and days in it? ex. If user input as 856 days the output should be 2 years 4 monthes 6 days.

Recommended Answers

All 3 Replies

Daniweb is not a homework service. Please provide some proof that you've attempted to write this program on your own.

No.
Instead, I'll give you this.

#include <iostream>

using namespace std;
#define KM_M  1000
#define M_CM  100
#define CM_MM 10

int main(){
    long long mm, cm, m, km;
    cout<<"Input number of kilometers:";
    cin>>km;
    cout<<"Input number of meters:";
    cin>>m;
    cout<<"Input number of centimeters:";
    cin>>cm;
    cout<<"Input number of millimeters:";
    cin>>mm;
    m+=km*KM_M;
    cm+=m*M_CM;
    mm+=cm*CM_MM;
    cout<<"Your total distance in millimeters is: "<<mm<<"mm.\n";
    return 0;
}

For a simple approach, first by dividing input by year, taking remainder and again do samething, except use months and days.
Now after you have coded them, post them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.