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


Please Help Members By Posting Answers For Below Questions

What is c method?

522


Why we use void main in c?

580


What is calloc()?

617


What are the types of c language?

541


Simplify the program segment if X = B then C ← true else C ← false

2573






Ow can I insert or delete a line (or record) in the middle of a file?

562


Explain how can I right-justify a string?

612


Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?

3041


What are the advantages and disadvantages of a heap?

692


a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none

620


what will be maximum number of comparisons when number of elements are given?

1395


Can a local variable be volatile in c?

567


Linked list is a Linear or non linear explain if linear how it working as a non linear data structures

1752


What are the types of data files?

713


please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code

1698