/* This is the twelveth lab of Lab EE107
The purpose of this lab for illustrating and determining tomorrow's date using
function and structures with a function "struct date dateUpdate (struct date today)."
to return an input argument for the struct.
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);
struct date_EU dateUpdate_EU(struct date_EU today);
int main(void) {
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);
// Calculate tomorrow's date
tomorrow_EU = dateUpdate_EU(today_EU);
// 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 ((d.year % 4 == 0 && d.year % 100 != 0) || d.year % 400 == 0)
daysPerMonth[1] == 29; // February has 29 days in a leap year
else
days = daysPerMonth[d.month - 1];
return days;
}
// Function to update the date to the next day
struct date_EU dateUpdate_EU(struct date_EU today) {
struct date_EU tomorrow;
int numberOfDays_EU(struct date_EU d);
// If it's not the end of the month
if (today.day != numberOfDays_EU(today)) {
tomorrow.day = today.day + 1;
tomorrow.month = today.month;
tomorrow.year = today.year;
}
else { // If it's the end of the month
if (today.month == 12) { // If it's the end of the year
tomorrow.day = 1;
tomorrow.month = 1;
tomorrow.year = today.year + 1;
}
else { // If it's not the end of the year
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year;
}
}
return tomorrow;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: