GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Sep-2008, 18:44
aedude94 aedude94 is offline
New Member
 
Join Date: Sep 2008
Posts: 5
aedude94 is an unknown quantity at this point

C++ and military time


Hi! I am a beginner at C++ and have to create this program that has you input two times in hh:mm:ss format and then add those two times together and output that new time in the same format. What I would like to know is, how are military times stored in C++? Like if I input 19:22:39 is that 192239 or like how? I don't understand how I can add the two times like that, and I don't understand how those times are like stored? Any help, not just writing how to do the entire thing please, would be very appreciated! Thanks
  #2  
Old 13-Sep-2008, 20:59
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: C++ and military time


Quote:
Originally Posted by aedude94
...you input two times in hh:mm:ss format and then add those two times together and output that new time in the same format.
You will need to study the functions defined in ctime.h:

http://www.cplusplus.com/reference/clibrary/ctime/

Note that none of these functions convert from a string representation to one of the common time structures. Given that you are a newcomer to C++, I suspect your instructor is wanting you to do all the conversions yourself. Decomposing a string into hours, minutes, & seconds can be done a number of ways; some of these methods include:
  • Use strtok() which is a traditionally a way C programmers would parse strings.
  • Use the string::substr() method.
  • Use the string::find_first_of() method.
All of these functions are described at sources such as cplusplus.com. Once you have isolated strings representing numeric values, you can use functions such as atoi() to convert to numeric values.

As for converting from one unit of time to another (eg. minutes -> hours, etc.), I tend to think that your instructor is wanting you to perform the appropriate arithmetic within your code.
  #3  
Old 14-Sep-2008, 13:45
aedude94 aedude94 is offline
New Member
 
Join Date: Sep 2008
Posts: 5
aedude94 is an unknown quantity at this point

Re: C++ and military time


Hey! Thank you so much! I can't believe my instructor just assumed we should know how to do this. haha. Oh well. Thank you again! (:
  #4  
Old 14-Sep-2008, 13:59
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: C++ and military time


Quote:
Originally Posted by aedude94
I can't believe my instructor just assumed we should know how to do this.
Perhaps you need to have your instructor clarify their intentions.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python - Need help with time card script/wage calculator sigkill9 Python Forum 5 12-Mar-2008 22:01
Looking for opinions crystalattice Miscellaneous Programming Forum 6 27-Sep-2006 22:02

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:57.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.