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
Is it acceptable to declare/define a variable in a c header?
A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM
Can you explain what keyboard debouncing is, and where and why we us it? please give some examples
How can I write a function that takes a format string and a variable number of arguments?
What are the benefits of c language?
What is the benefit of using an enum rather than a #define constant?
What are the types of operators in c?
What is structure in c definition?
How can I read data from data files with particular formats?
Where define directive used?
What is an example of structure?
What is gets() function?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
Why c is called a mid level programming language?
Is it cc or c in a letter?