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 / muhammad ali

#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;
system("pause");
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 ?    65 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you convert strings to numbers in C?

704


What do you mean by scope of a variable in c?

538


can we implement multi-threads in c.

656


Wt are the Buses in C Language

2744


Is c pass by value or reference?

593






Tell me what are bitwise shift operators?

650


Explain high-order bytes.

670


Explain can static variables be declared in a header file?

669


What is the difference between #include and #include 'file' ?

602


Write a program to show the change in position of a cursor using c

573


How can I pad a string to a known length?

607


What is meant by initialization and how we initialize a variable?

581


int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above

738


What is declaration and definition in c?

521


write a programming in c to find the sum of all elements in an array through function.

1700