In: Computer Science
Hi I started writing this program but is confusing the heck out of me and I don't know if I'm just over thinking it too much. Can anyone help me with this? Write a program in c language: simulates a time clock does nested for loops with one switch statement. Declares variables hours, minutes, seconds as integers. For hours are zero to < 24 however switch when hours are greater than 24 print on new line “25 error” switch when hours are thirteen break switches otherwise by default print on new line “top of the hour!” , For minutes are zero to 60, For seconds are zero to 60 in this loop print on a line hours value separated by a colon character minutes value separated by a colon character seconds value with new line character. Just before ending print on new line “Program finished!” then terminate program.
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
int hour=0;
int min=0;
int sec=0;
while(1)
{
system("clear");
printf("%02d : %02d :
%02d \n",hour,min,sec);
fflush(stdout);
sec++;
if(sec==60){
min+=1;
sec=0;
}
if(min==60){
hour+=1;
min=0;
}
if(hour==24){
hour=0;
min=0;
sec=0;
}
if (hour>24)
{
printf("25 error");
}
printf("Program
finished! \n");
sleep(1);
}
return 0;
}