2. Write a function called hms_to_secs() that takes
three int values—for hours, minutes, and seconds—as
arguments, and returns the equivalent time in seconds..
Create a program that exercises this function by repeatedly
obtaining a time value in hours, minutes, and seconds from
the user (format 12:59:59), calling the function, and
displaying the value of seconds it returns.

Answer Posted / htoo cherry

#include <iostream >
Using namespace std ;
long hms_to_secs (int, int, int) ;
int main ()
{int hrs, min, sec;
cout <<"Enter hours" <<endl ;cin>>hrs;
cout <<"Enter minutes " <<endl ;cin>>min;
cout <<"Enter seconds" <<endl ;cin <<sec;
cout <<hrs<<":" <<min<<":" <<sec<<":" <<endl ;
cout <<The time in seconds<<hms_to_secs (int hrs, int min, int sec) ;
}
long hms_to_secs (int h, int m, int s)
return( h*3600+m*60+s);

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What's a good way to check for "close enough" floating-point equality?

616


Explain how does free() know explain how much memory to release?

563


How can I get the current date or time of day in a c program?

643


What does typedef struct mean?

644


What is the difference between volatile and const volatile?

554






Explain logical errors? Compare with syntax errors.

617


An application package has been provided to you without any documents for the following application. The application needs to be tested. How will you proceed?

658


How many levels of pointers can you have?

694


What are external variables in c?

535


What is advantage of pointer in c?

680


What is the difference between ++a and a++?

679


What is a void pointer in c?

597


There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?

802


Difference between malloc() and calloc() function?

646


How can I read a binary data file properly?

625