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 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is c called "mother" language?

851


What is file in c preprocessor?

646


What is s or c?

589


How many types of errors are there in c language? Explain

565


What is sizeof c?

604






Why is C language being considered a middle level language?

649


Why c is faster than c++?

625


please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com

1318


write a program to find out prime number using sieve case?

1631


any C program contains only one function, it must be a) void () b) main () c) message () d) abc ()

689


What does the format %10.2 mean when included in a printf statement?

1079


Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].

634


How are pointers declared in c?

592


how to find anagram without using string functions using only loops in c programming

2710


the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none

639