Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need suggestion

Status
Not open for further replies.

pavillion

IS-IT--Management
Jul 10, 2007
3
CA

hi, I need your help and would like to know how and whats the best technique you programmers would use to solve this problem. Ok, this program that IM going to be making has a start and end time reserve.And It will also ask a user to enter a start and end time. Now C++ will try to add it but first it has to check if the user input time will overlap with the reserve time.


for example:

the reserve time is-->lets say,
Reserve time=10:30 to 11:50
so, if the user enters a time between 10:30 and 11:50 C++
should refuse. If User enters 9:30 thru 10:29 then C+ would add.

This is what I was thinking of using to validate,do you think this will work?

if(Input_Hour==Reserve_Hour)
{
if(Input_End_Minute<Reserve_Start_minute)
{ cout<<&quot;OK add&quot;;
}
}
else
{ cout<<&quot;NO add&quot;;
}

 
I'd do something like this:

int input_time = Input_hour*60+input_minute;

if(input_time>=reserve_start_hour*60+reserve_start_minute)&&(input_time<=reserve_end_hour*60+reserve_end_minute)
...
although if you had a reserve time spanning midnight you'd have to do a different check if reserve_end<reserve_start. :) Hope that this helped! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top