Create a structure called time. Its three members, all of type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This can be in 12:30:50 format. The program then stores the time in a variable of type time, and finally prints out the total number of seconds.
#include<stdio.h>
struct time
{
int Hour;
int Minute;
int Second;
};
int main()
{
struct time t1;
false :
printf("\nEnter Hour:");
scanf("%d",&t1.Hour);
if(t1.Hour>24)
{
printf("\nWrong Hour !");
goto false ;
}
false1 :
printf("\nEnter Minute:");
scanf("%d",&t1.Minute);
if(t1.Minute>60)
{
printf("\nWrong Minute !");
goto false1 ;
}
false2 :
printf("\nEnter the Second:");
scanf("%d",&t1.Second);
if(t1.Second>60)
{
printf("\nWrong Second !");
goto false2 ;
}
printf("\nThe Entered Time is : %d:%d:%d",t1.Hour,t1.Minute,t1.Second);
long s = t1.Hour*3600 + t1.Minute*60 + t1.Second;
printf("\nThe total seconds is : %ld seconds",s);
}
Comments
Leave a comment