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 / alex chogo
#include<iostream>
using namespace std;
long hms_to_sec(int hr,int mn, int sec);
int main()
{
int hr,mn,sec;
cout<<hms_to_sec(hr,mn,sec);
return 0;
}
long hms_to_sec(int hr,int mn, int sec)
{
cout << "please enter hr, min, and sec" << endl;
cin >> hr>> mn>> sec;
return (hr*60*60)+(mn*60)+ sec;
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
What does return 1 means in c?
What are the __date__ and __time__ preprocessor commands?
How will you divide two numbers in a MACRO?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
Where is volatile variable stored?
What is the difference between array and pointer in c?
What is a function in c?
Tell us bitwise shift operators?
C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions
Is anything faster than c?
What is substring in c?
code for find determinent of amatrix
How the c program is executed?
How can I handle floating-point exceptions gracefully?