Skip to content

Commit

Permalink
Converts a date to the day of the year, determines days left in the year
Browse files Browse the repository at this point in the history
  • Loading branch information
JayMburu committed Mar 17, 2022
1 parent 95cf4dd commit 33faf29
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 0x03-debugging/3-print_remaining_days.c
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);
}
}
}

0 comments on commit 33faf29

Please sign in to comment.