Need help with time


charges & start time:
1-5 ---> .15
6-9 ---> .20

let says I input

4 for the starting time

and

7 for the length of the call

I know that I will have (1*.20) and (2*.15)

how can I write this in code?

I tried Do-While loop, for, ......
Last edited on
You should post your try to get help.
what you mean? the coding?
Yes, the code that you have written so far.

Btw, your description of the problem could be more clear.
So far I just wrote asked user to input the starting time of call and length of the call.

let says that user input (enter) the starting time is at 4:00 pm and the call least for 7 hours...

since it is start at 4:00 pm and goes to 5:00 pm. In that time the rate of the calling is .15 and since doesn't stop at 5:00 pm, So remainder 3 hours should be at 6-9 hours and In that time the rate is .20.

is here the equation I come up:

(1*.15) <----- for the 1 hour.
(3*.20) <----- for remainder hours.

.15 + .60 = 0.75



how can i write in C++ coding?


the rest of coding are same
Last edited on
Your math ...

It seems by your example that "calls" are "whole hours". Calls starting 1pm, 2pm, 3pm, or 4pm should charge .15 per hour and calls starting at 6pm, 7pm, or 8pm charge .2 per hour.

Now, your example call starts 4pm and could be split to 7 one hour calls. The first is .15. The second from 5pm to 6pm is apparently free. Then, the next three from 6pm to 9pm charge .2 each, and the last two are again free.

You have the starting time and duration.
If it is less than 1pm, you decrease the difference from the duration.

If there is any duration left, then you take the minimum of duration and .15 period and use that to charge with .15. Reduce the time from duration.

If any duration is left, do similar step with the .2 period.

Actually, if the duration goes around the clock, you should at start take as many days off the duration as possible (a division&modulus) and add their charge.
It's is time clock.
Topic archived. No new replies allowed.