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.
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / 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 | 3 No |
Answer / celestine
#include<iostream>
#include<cstdlib>
using namespace std;
long hms_to_secs(int hr, int min, int sec){
long secs =0;
secs = (hr * 60 * 60)+(min * 60)+sec;
return secs;
}
int main(){
int hr,min,sec; long secs;
cout<<"Enter Hours: ";cin>>hr;
cout<<"Enter Minutes: ";cin>>min;
cout<<"Enter Seconds: ";cin>>sec;
secs = hms_to_secs(hr,min,sec);
cout<<"Seconds is: "<<secs<<endl;
system("pause");
return 0;
}
Is This Answer Correct ? | 9 Yes | 4 No |
Answer / htoo cherry
#include <iostream >
Using namespace std ;
long hms_to_secs (int, int, int) ;
int main ()
{int hrs, min, sec;
cout <<"Enter hours" <<endl ;cin>>hrs;
cout <<"Enter minutes " <<endl ;cin>>min;
cout <<"Enter seconds" <<endl ;cin <<sec;
cout <<hrs<<":" <<min<<":" <<sec<<":" <<endl ;
cout <<The time in seconds<<hms_to_secs (int hrs, int min, int sec) ;
}
long hms_to_secs (int h, int m, int s)
return( h*3600+m*60+s);
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / alex chogo
#include<iostream>
using namespace std;
long hms_to_sec(int hr,int mn, int sec);
int main()
{
int hr,mn,sec;
cout<<hms_to_sec(hr,mn,sec);
return 0;
}
long hms_to_sec(int hr,int mn, int sec)
{
cout << "please enter hr, min, and sec" << endl;
cin >> hr>> mn>> sec;
return (hr*60*60)+(mn*60)+ sec;
}
Is This Answer Correct ? | 1 Yes | 1 No |
What is character constants?
Find the largest number from the given 2 numbers without using any loops and the conditional operator.
What does the message "warning: macro replacement within a string literal" mean?
What is LINKED LIST? How can you access the last element in a linked list?
What is the purpose of 'register' keyword in c language?
What is the difference between memcpy and memmove?
without a terminator how can we print a message in a printf () function.
why do we use # in c-language?
Differentiate between calloc and malloc.
What are header files in c?
What is array in C
if function is declared as static in one source file, if I would like to use the same function in some other source file...is it possible....how ?