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 / celestine
#include<iostream>
#include<cstdlib>
using namespace std;
long hms_to_secs(int hr, int min, int sec){
long secs =0;
secs = (hr * 60 * 60)+(min * 60)+sec;
return secs;
}
int main(){
int hr,min,sec; long secs;
cout<<"Enter Hours: ";cin>>hr;
cout<<"Enter Minutes: ";cin>>min;
cout<<"Enter Seconds: ";cin>>sec;
secs = hms_to_secs(hr,min,sec);
cout<<"Seconds is: "<<secs<<endl;
system("pause");
return 0;
}
| Is This Answer Correct ? | 9 Yes | 4 No |
Post New Answer View All Answers
What are reserved words?
Implement bit Array in C.
Explain how can I avoid the abort, retry, fail messages?
what is a function method?give example?
Can include files be nested? How many levels deep can include files be nested?
What are compound statements?
a program that can input number of records and can view it again the record
How a string is stored in c?
What is clrscr in c?
What are operators in c?
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
What is %g in c?
How do I convert a string to all upper or lower case?
What is the purpose of main( ) in c language?
What is the difference between single charater constant and string constant?