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 is null defined in c?

862


Why clrscr is used after variable declaration?

1312


Explain zero based addressing.

783


What is the size of empty structure in c?

812


What is the right way to use errno?

827


Is swift based on c?

854


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

857


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

991


What are types of preprocessor in c?

812


How can I make it pause before closing the program output window?

795


How do we make a global variable accessible across files? Explain the extern keyword?

1634


How can I call fortran?

814


Why does everyone say not to use scanf? What should I use instead?

1079


What are enumerated types?

851


Can you apply link and association interchangeably?

892