Mini calendar C

i just finished successfully the project, here is my solution:

#include <stdio.h>
#include <stdbool.h>

bool is_leap_year(int year) {
  if (year % 4 != 0) {
    return false;
  } else if (year % 100 != 0) {
    return true;
  } else if (year % 400 != 0){
    return false;
  } else {
    return true;
  }
}

int days_in_month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void add_days_to_date(int *mm, int *dd, int *yy, int days_left_to_add) {
int days_left_in_month;
while (days_left_to_add > 0) {
  days_left_in_month = days_in_month[*mm] - *dd;
  if (*mm == 2 && is_leap_year(*yy)) {
    days_left_in_month++;
  }
if (days_left_to_add >= days_left_in_month) {
  days_left_to_add -= days_left_in_month;
  *dd = 1;
  days_left_to_add--;
  if (*mm != 12) {
    *mm = *mm + 1;
  } else {
    *mm = 1;
    *yy = *yy + 1;
  }
} else {
  *dd +=  days_left_to_add;
  days_left_to_add = 0;
}
}
}

int main() {
int mm, dd, yy, days_left_to_add;
printf("mm dd yy num:\n");
scanf("%d%d%d%d", &mm, &dd, &yy, &days_left_to_add);
add_days_to_date(&mm, &dd, &yy, days_left_to_add);
printf("%d %d %d\n", mm, dd, yy);

//  int year;
//  printf("write an year\n");
//  scanf("%d", &year);
//  if (is_leap_year(year)) {
//    printf("it is a leap year\n");
//  } else {
//    printf("it is not a leap year\n");
//  }
}
1 Like

Thank’s dude, you save us a lot