-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converts a date to the day of the year, determines days left in the year
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
#include "main.h" | ||
|
||
/** | ||
* print_remaining_days - takes a date and prints how many days are | ||
* left in the year, taking leap years into account | ||
* @month: month in number format | ||
* @day: day of month | ||
* @year: year | ||
* Return: void | ||
*/ | ||
|
||
void print_remaining_days(int month, int day, int year) | ||
{ | ||
if ((year % 4 == 0 && !(year % 100 == 0)) || year % 400 == 0) | ||
{ | ||
if (month > 2 && day >= 60) | ||
{ | ||
day++; | ||
} | ||
|
||
printf("Day of the year: %d\n", day); | ||
printf("Remaining days: %d\n", 366 - day); | ||
} | ||
else | ||
{ | ||
if (month == 2 && day == 60) | ||
{ | ||
printf("Invalid date: %02d/%02d/%04d\n", month, day - 31, year); | ||
} | ||
else | ||
{ | ||
printf("Day of the year: %d\n", day); | ||
printf("Remaining days: %d\n", 365 - day); | ||
} | ||
} | ||
} |