Discount for a call between two times
Dec 15, 2016 at 11:30am UTC
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;
Dec 15, 2016 at 11:37am UTC
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
Dec 15, 2016 at 11:58am UTC
@shadder
How should I correct that then? Or what is the right solution for this calculation.
Dec 15, 2016 at 12:04pm UTC
You may convert (standardize) time to minutes and then compare the time
Dec 15, 2016 at 12:16pm UTC
@shadder what do you mean by that?
Dec 15, 2016 at 2:32pm UTC
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 Dec 15, 2016 at 2:32pm UTC
Dec 15, 2016 at 9:32pm UTC
http://www.cplusplus.com/forum/beginner/204718/
Topic archived. No new replies allowed.