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
What is use of bit field?
can any one tel me wt is the question pattern for NIC exam
Why do we use pointer to pointer in c?
Is c weakly typed?
How can this be legal c?
Why c language?
What is %s and %d in c?
Differentiate between #include<...> and #include '...'
Is c is a low level language?
Is it better to bitshift a value than to multiply by 2?
what are the different storage classes in c?
What are data structures in c and how to use them?
Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.
What is pragma in c?
What is the difference between %d and %i?