/* This is the twelveth lab of Lab EE107
The purpose of this lab for illustrating and determining the time of next second
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>
// Define a structure for time
struct time_EU {
int hour;
int minutes;
int seconds;
};
// Function prototype
struct time_EU timeUpdate_EU(struct time_EU now);
int main(void) {
struct time_EU timeUpdate_EU(struct time_EU now);
struct time_EU currentTime_EU, nextTime_EU;
// Get the current time from the user
printf("Enter the time (hh:mm:ss): ");
scanf("%i:%i:%i", ¤tTime_EU.hour, ¤tTime_EU.minutes, ¤tTime_EU.seconds);
// Update the time by one second
nextTime_EU = timeUpdate_EU(currentTime_EU);
// Print the updated time
printf("Updated time is %.2i:%.2i:%.2i\n", nextTime_EU.hour, nextTime_EU.minutes, nextTime_EU.seconds);
return 0;
}
// Function to update the time by one second
struct time_EU timeUpdate_EU(struct time_EU now) {
++now.seconds; // Increment seconds
// If seconds reach 60, reset to 0 and increment minutes
if (now.seconds == 60) {
now.seconds = 0;
++now.minutes;
}
// If minutes reach 60, reset to 0 and increment hours
if (now.minutes == 60) {
now.minutes = 0;
++now.hour;
}
// If hours reach 24, reset to 0 (midnight)
if (now.hour == 24) {
now.hour = 0;
}
// Return the updated time
return now;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: