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 the 4 data types?
What is the purpose of main( ) in c language?
Is a pointer a kind of array?
Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.
How can I change the size of the dynamically allocated array?
List a few unconditional control statement in c.
Who invented bcpl language?
How can I remove the trailing spaces from a string?
How would you rename a function in C?
What is variable and explain rules to declare variable in c?
When was c language developed?
Write a program to print numbers from 1 to 100 without using loop in c?
When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)
Is there sort function in c?