0

im working on something and i need the user to be able to enter times that things start and end. i need to know how i can store that and then compare them later. they need to be able to enter like 12:45. i was thinking i could somehow ignore the colon or something and just store 1245 as an int but i dont know how. any help is appreciated.

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Karkaroff
0

error checking and "dummy proofing" aside, you can probably store the input value to a string variable, then use the string methods with loops to process the string. Specifically, erase and find_first_of may be of interest:
http://www.cplusplus.com/reference/string/string/

to get integer from a string, use atoi(strConvert.c_str())

I would imagine actually getting it to work is your homework or something, so I won't give a detailed solution.

0

You could try the scanf function...

int h,m;
scanf("%d:%d",&h,&m);

You can enter the time as xx:xx

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.