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 / jay
#include<iostream>
using namespace std;
int hms_to_sec(int hr,int min, int sec);
int main()
{
int hr,min,sec;
int result =hms_to_sec(hr,min,sec);
cout << "result = " << result;
return 0;
}
int hms_to_sec(int hr,int min, int sec)
{
int seconds =0;
cout << "please enter hr" << endl;
cin >> hr;
cout << "please enter min" << endl;
cin >> min;
cout << "please enter sec" << endl;
cin >> sec;
seconds = (hr*60*60)+(min*60)+sec;
return seconds;
}
| Is This Answer Correct ? | 20 Yes | 4 No |
Post New Answer View All Answers
a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none
what is the height of tree if leaf node is at level 3. please explain
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
What does 4d mean in c?
What are the similarities between c and c++?
Explain what standard functions are available to manipulate strings?
Is printf a keyword?
c language interview questions & answer
Define and explain about ! Operator?
What are Macros? What are its advantages and disadvantages?
What are global variables and how do you declare them?
How can I find the modification date of a file?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
What is assert and when would I use it?
please explain every phase in the "SDLC" in the dotnet.