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


Please Help Members By Posting Answers For Below Questions

What are the various types of control structures in programming?

622


What do you mean by recursion in c?

620


shorting algorithmS

1794


What is binary tree in c?

617


How do I determine whether a character is numeric, alphabetic, and so on?

618






typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?

1066


What is huge pointer in c?

575


How can I write a function that takes a format string and a variable number of arguments?

600


a c code by using memory allocation for add ,multiply of sprase matrixes

2294


Explain how can I convert a string to a number?

639


explain what are actual arguments?

630


Which control loop is recommended if you have to execute set of statements for fixed number of times?

803


What does node * mean?

704


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.

643


Which is better pointer or array?

592