Code:
#define hours 20
#define min 12
#define sec 15
int time (int h, int m, int s, int runh, int runm, int runs);
#include <stdio.h>
int main (void) {
int ans = 0, timeh = 0, timem = 0, times = 0;
int timehr, timemr, timesr, i;
while (ans != 3) {
printf("Choose one of the following menu options:\1. set time\n 2. start timer\n 3. quit\n");
scanf("%d", &ans);
if (ans > 3){
printf("Sorry, that is not a valid menu choice.\n\n");
printf("Choose one of the following menu options:\n1: set time\n2: start timer\n3: quit\n");
scanf("%d", &ans);
}
if (ans == 1) {
printf("What is the current time?\n");
scanf("%d : %d : %d", &timeh, &timem, ×);
if (timeh > hours || timem > min || times > sec) {
printf("Time is invalid please enter again\n");
scanf("%d : %d : %d", &timeh, &timem, ×);
}
}
else if (ans == 2) {
printf("How long would you like me to count?\n");
scanf("%d : %d : %d", &timehr, &timemr, ×r);
printf("\nHERE WE GO!\n");
time(timeh, timem, times, timehr, timemr, timesr);
}
}
printf("\nThank You!\n");
return 0;
}
int time (int h, int m, int s, int runh, int runm, int runs) {
int i;
if (runs > 0){
for (i=0; i<runs; i++){
if (s+1 > sec){
s = 0;
if (m+1 > min){
m = 0;
if (h+1 > hours)
h = 0;
else
h = h+1;
}
else
m = m+1;
}
else
s = s+1;
printf("%d:%d:%d\n", h, m, s);
}
}
if (runm > 0) {
for (i=0; i<(runm*sec)+1; i++) {
if (s+1 > sec){
s = 0;
if (m+1 > min){
m = 0;
if (h+1 > hours)
h = 0;
else
h = h+1;
}
else
m = m+1;
}
else
s = s+1;
printf("%d:%d:%d\n", h, m, s);
}
}
if (runh > 0) {
for (i=0; i<(((runh*min)+ 1)*(sec+1)); i++) {
if (s+1 > sec){
s = 0;
if (m+1 > min){
m = 0;
if (h+1 > hours)
h = 0;
else
h = h+1;
}
else
m = m+1;
}
else
s = s+1;
printf("%d:%d:%d\n", h, m, s);
}
}
printf("\nDONE COUNTING!\n\n");
}