Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (anonymous):

hi guys can you help me out here .i am trying to write a programe in C++ that obtain time in hours and minutes using a separate function (not main ) and calculate charges based on that time .so i want to know how can i use that time on the next function ?

OpenStudy (anonymous):

Calling the time function from the ctime or time.h libraries will give you the hours since January 1st, 1970. You can then deduct the starting time from that number and get the time difference in hours. Once you have that number, you can calculate the charges and return the charge as a double and you're done. See the demo on http://www.cplusplus.com/reference/clibrary/ctime/time/. Technically its in C (that's where your printf statement is coming from) but it should work in C++.

OpenStudy (anonymous):

Sounds interesting...what have you got? Could you post the requirements or the source code?

OpenStudy (rsmith6559):

The time functions return the seconds from the epoch (Jan 1, 1970 00:00:01 GMT), not the hours. The hours were calculated in the printf statement.

OpenStudy (anonymous):

Hey thanks! Forgot that! That way (after adjusting time zone issues) you can calculate the hours AND the minutes by dividing by 60. please Please PLEASE post your code man. I would LOVE to play with it!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!