Write a program which accepts days as integer and display total number of years, months and days in it.
For example: If user input as 856 days the output should be 2 years 4 months 6 days.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <iostream> using namespace std; int main() { int days, years, months, remainingDays; cout << "Enter the number of days: "; cin >> days; years = days / 365; // Calculate years days = days % 365; // Remaining days after calculating years months = days / 30; // Calculate months remainingDays = days % 30; // Remaining days after calculating months cout << "Equivalent: " << years << " years " << months << " months " << remainingDays << " days." << endl; return 0; } |
Output
Enter the number of days: 45
Equivalent: 0 years 1 months 15 days.