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
Differentiate between declaring a variable and defining a variable?
what is ur strangth & weekness
Explain how can I make sure that my program is the only one accessing a file?
What are identifiers in c?
what will be the output for the following main() { printf("hi" "hello"); }
What are the advantages of the functions?
The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference
What is static and auto variables in c?
Where in memory are my variables stored?
What is the general form of a C program?
Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?
write an algorithm to display a square matrix.
What is enumerated data type in c?
What is the use of ?: Operator?
Explain what is output redirection?