Discount for a call between two times

I'm trying to calculate the price for a call(24-hour clock). I want the caller to get a discount of the price if she/he DON'T talk between 08:00 and 18:30. I tried to do a if-statement as you see below but the calculations I get are wrong. Please help.

1
2
3
4
if((startHour>=8 && startMinute>=0) && (endHour<=18 && endMinute<=30))
    totPrice=totMinutes*pricePerMiunte;
else
    totPrice=totMinutes*pricePerMiunte*discount;
lets say the time is 12:45

so

startHour>=8 true
startMinute>=0 true

endHour<=18 true
endMinute<=30 false

so this may be the problem because of which your are getting wrong calculations
@shadder
How should I correct that then? Or what is the right solution for this calculation.
You may convert (standardize) time to minutes and then compare the time
@shadder what do you mean by that?
convert hours to minutes

1
2
3
int minute=0;
minute+=(startHour*60);//1 hr is 60 min
minute+=startMinute;


so you'll get a value

so with the help of basic maths and some coding you'll achieve your desired code
Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/204718/
Topic archived. No new replies allowed.