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 various types of control structures in programming?
What do you mean by recursion in c?
shorting algorithmS
What is binary tree in c?
How do I determine whether a character is numeric, alphabetic, and so on?
typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?
What is huge pointer in c?
How can I write a function that takes a format string and a variable number of arguments?
a c code by using memory allocation for add ,multiply of sprase matrixes
Explain how can I convert a string to a number?
explain what are actual arguments?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
What does node * mean?
Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.
Which is better pointer or array?