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 is the ANSI C Standard?
C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions
How to declare pointer variables?
All technical questions
How do I get an accurate error status return from system on ms-dos?
What is scope rule in c?
How do I convert a string to all upper or lower case?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
How can I prevent another program from modifying part of a file that I am modifying?
What does & mean in scanf?
Explain the properties of union. What is the size of a union variable
Which programming language is best for getting job 2020?
write a program to concatenation the string using switch case?
Write a program to find the biggest number of three numbers in c?
Write a C program in Fibonacci series.