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 / jay

#include<iostream>
using namespace std;
int hms_to_sec(int hr,int min, int sec);
int main()
{
int hr,min,sec;


int result =hms_to_sec(hr,min,sec);
cout << "result = " << result;
return 0;
}

int hms_to_sec(int hr,int min, int sec)
{
int seconds =0;
cout << "please enter hr" << endl;
cin >> hr;
cout << "please enter min" << endl;
cin >> min;
cout << "please enter sec" << endl;
cin >> sec;

seconds = (hr*60*60)+(min*60)+sec;
return seconds;

}

Is This Answer Correct ?    20 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is #define used?

1016


What is variable in c example?

812


How many parameters should a function have?

877


Explain how do you determine the length of a string value that was stored in a variable?

914


State two uses of pointers in C?

825


the process of defining something in terms of itself is called (or) in C it is possible for the functions to call themselves. A function called a) nested function b) void function c) recursive function d) indifinite function

1021


How can you increase the allowable number of simultaneously open files?

824


What is meant by preprocessor in c?

737


What are pointers? What are stacks and queues?

782


How can I avoid the abort, retry, fail messages?

868


What is strcpy() function?

868


How many types of operators are there in c?

805


What are structure members?

824


how to create duplicate link list using C???

2277


What is a global variable in c?

777