You are here:

C++/Cin an int a char and an int


Hi i am doing a home work assingnment that requires the user to enter the time they arrive and leave a parking garage. The instructor wants the format in HR:MIN he gives a hint that says "use cin to obtain the values, cin >> and int, a char, and an int". I also have to be able to compare the entry and exit time to make sure they entered before they left. I am not quite sure how to do this because as far as i know the variable name i use to store the time cant be both an int and a char. I am having no problems with the rest of the assignment other than this part that has me stumped.

I am using VB2008.



You can cin to both variables.  By int, char, int, I think that means get the hours, ':', and minutes, like:

int hr, min;
char colon;

cin >> hr >> colon >> min;

To compare times, it's easier to convert to, e.g., minutes and then compare.

int minsOfEntry = hr * 60 + min;

Then minsOfEntry has to be < minsOfExit (which you calculate in the same way).  If it's an overnight garage, it gets more complicated of course. :-)

Hope this helps,


All Answers

Answers by Expert:

Ask Experts


Bill A


I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.


I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

BS Computer Engineering

©2017 All rights reserved.