Answer to Question #265560 in C++ for Usama

Question #265560

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.


1
Expert's answer
2021-11-21T17:39:47-0500
#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);


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS