CYB126-Projects/Homework2/dhms.c
2023-09-27 20:07:19 -07:00

40 lines
No EOL
1.3 KiB
C

// header files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
// local constants
#define SECONDS_IN_DAY 86400
#define SECONDS_IN_HOUR 3600
#define SECONDS_IN_MINUTE 60
#define TIME_CONSTANT_SECONDS 8675309
/*
Name: Day/Hour/Minute/Second Calculator
Process: Given a number of seconds,
figure out how many days, hours, minutes and seconds fits.
Function input/parameters: NONE
Function output/parameters: NONE
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
int main()
{
// define local variables
int totalDays, totalHours, totalMinutes, totalSeconds;
// do calculations
// need to modulo then divide by last time unit for each part.
totalSeconds = TIME_CONSTANT_SECONDS % SECONDS_IN_MINUTE;
totalMinutes = (TIME_CONSTANT_SECONDS % SECONDS_IN_HOUR) / SECONDS_IN_MINUTE;
totalHours = (TIME_CONSTANT_SECONDS % SECONDS_IN_DAY) / SECONDS_IN_HOUR;
totalDays = (TIME_CONSTANT_SECONDS % (SECONDS_IN_DAY * 30)) / SECONDS_IN_DAY;
// display results
printf("In %d seconds, there are: %d days, %d hours, %d minutes, %d seconds\n",
TIME_CONSTANT_SECONDS, totalDays, totalHours, totalMinutes, totalSeconds);
// return success
return 0;
}