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
If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..
What is the data segment that is followed by c?
What is the description for syntax errors?
Is fortran faster than c?
Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;
write an algorithm to display a square matrix.
What is the difference between typedef struct and struct?
What is selection sort in c?
How macro execution is faster than function ?
Explain about the functions strcat() and strcmp()?
Explain what is a static function?
What is the advantage of using #define to declare a constant?
Can a variable be both const and volatile?
List out few of the applications that make use of Multilinked Structures?
Are negative numbers true in c?