Problem: Write a program in C++ that takes a certain value of number of days as input and displays the total number of years, months and days in it. (ex. 500 days= 1 year 4 months and 15 days)

Code: 

#include <iostream>

using namespace std;

int main(){
    int input, dd, mm1, mm, yy;



    cout << "Enter the number of days: ";
    cin >> input;

    yy = input/365;

    mm1 = input%365;
    mm = mm1/30;

    dd = mm1%30;

    cout << input <<" days = "<< yy << " year(s) " << mm << " month(s) " << dd << " day(s)";
}

Output: 

Enter the number of days: 500
500 days = 1 year(s) 4 month(s) 15 day(s)
Process returned 0 (0x0)   execution time : 5.008 s
Press any key to continue.

أحدث أقدم