C++ program to convert the days into years, weeks, and days
ADVERTISEMENTS
In this article, you will learn how to convert the days into years, weeks, and days in the c++ language.
You should have the knowledge of the following topics in c++ programming to understand this program:
- C++
main()
function - C++
cin
object - C++
cout
object
Base Knowledge
1Year = 365days
1Week = 7days
Standard formula to calculate the year, weeks, and days
y = (d / 365)
w = (d % 365) / 7
d = d - ((y * 365) + (w))
Where
y = year
w = week
d = day
Source Code
// C++ program to convert days into years, weeks and days
#include <iostream>
using namespace std;
int main() {
int d, y, w;
// d = days
// y = years
// w = weeks
cout << "Enter the days::\n";
cin >> d;
/* Conversion of days in to years, weeks and days */
y = (d / 365);
w = (d % 365) / 7;
d = d - ((y * 365) + (w));
// Output
cout << "\n" << y << " Year, " << w << " Weeks, and " << d << " Days\n";
return 0;
}
Output
Enter the days::
464
1 Year, 14 Weeks, and 85 Days
Explanation
In this above program, we have taken an input 464
number of total days then used the standard formula to calculate the number of years, number of weeks, and number of days then It returned the following values:
- 1 Year
- 14 Weeks
- 85 Days