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



2. Write a function called hms_to_secs() that takes three int values—for hours, minutes,..

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

2. Write a function called hms_to_secs() that takes three int values&#8212;for hours, minutes,..

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

2. Write a function called hms_to_secs() that takes three int values&#8212;for hours, minutes,..

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

2. Write a function called hms_to_secs() that takes three int values&#8212;for hours, minutes,..

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

2. Write a function called hms_to_secs() that takes three int values&#8212;for hours, minutes,..

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

Post New Answer

More C Interview Questions

What is character constants?

0 Answers  


Find the largest number from the given 2 numbers without using any loops and the conditional operator.

2 Answers  


What does the message "warning: macro replacement within a string literal" mean?

1 Answers  


What is LINKED LIST? How can you access the last element in a linked list?

0 Answers   ADP,


What is the purpose of 'register' keyword in c language?

0 Answers  






What is the difference between memcpy and memmove?

0 Answers  


without a terminator how can we print a message in a printf () function.

7 Answers   NIIT,


why do we use # in c-language?

1 Answers  


Differentiate between calloc and malloc.

0 Answers   Wipro,


What are header files in c?

0 Answers  


What is array in C

0 Answers  


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 ?

2 Answers   NetApp,


Categories