/* This is the twelveth lab of Lab EE107
The purpose of this lab for illustrating and determining tomorrow's date using
function and structures.

Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 16th, 2024.
*/

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

// Define a structure for date
struct date_EU {
    int month;
    int day;
    int year;
};

// Function prototypes
int numberOfDays_EU(struct date_EU d);
bool isLeapYear_EU(struct date_EU d);

int main(void) {
    // Declare variables for today and tomorrow's date
    struct date_EU today_EU, tomorrow_EU;

    // Get today's date from the user
    printf("Enter today's date (mm dd yyyy): ");
    scanf("%i%i%i", &today_EU.month, &today_EU.day, &today_EU.year);
    printf("%i/%i/%i \n", today_EU.month, today_EU.day, today_EU.year);

    // Calculate tomorrow's date
    if (today_EU.day != numberOfDays_EU(today_EU)) {
        tomorrow_EU.day = today_EU.day + 1;
        tomorrow_EU.month = today_EU.month;
        tomorrow_EU.year = today_EU.year;
    }
    else if (today_EU.month == 12) { // If it's the end of the year
        tomorrow_EU.day = 1;
        tomorrow_EU.month = 1;
        tomorrow_EU.year = today_EU.year + 1;
    }
    else { // If it's the end of the month
        tomorrow_EU.day = 1;
        tomorrow_EU.month = today_EU.month + 1;
        tomorrow_EU.year = today_EU.year;
    }

    // Print tomorrow's date
    printf("Tomorrow's date is %i/%i/%.2i.\n", tomorrow_EU.month, tomorrow_EU.day, tomorrow_EU.year % 100);


    return 0;
}

// Function to find the number of days in a month
int numberOfDays_EU(struct date_EU d) {
    int days;
    const int daysPerMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    // Check if it's a leap year and adjust days for February
    if (isLeapYear_EU(d) == true && d.month == 2)
        days = 29;
    else
        days = daysPerMonth[d.month - 1];

    return days;
}

// Function to determine if it's a leap year
bool isLeapYear_EU(struct date_EU d) {
    bool leapYearFlag;

    // Check leap year conditions
    if ((d.year % 4 == 0 && d.year % 100 != 0) || d.year % 400 == 0)
        leapYearFlag = true; // It's a leap year
    else
        leapYearFlag = false; // Not a leap year

    return leapYearFlag;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: