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
Write a code to determine the total number of stops an elevator would take to serve N number of people.
What is && in c programming?
Explain the process of converting a Tree into a Binary Tree.
Can you mix old-style and new-style function syntax?
How do I create a directory? How do I remove a directory (and its contents)?
Why is python slower than c?
Differentiate between new and malloc(), delete and free() ?
What is the difference between volatile and const volatile?
What are examples of structures?
Explain how do I determine whether a character is numeric, alphabetic, and so on?
What are bitwise shift operators in c programming?
Who developed c language?
What is a scope resolution operator in c?
What is the difference between near, far and huge pointers?
Is it possible to initialize a variable at the time it was declared?