One great problem solving strategy is to make the hard problem into an easier one, solve the easy one, and take what you learned and evolve it into a solution to the harder problem. Below is a problem I will call Phone Lite. It is easier than the Phone problems on the preceeding link. Try this one first if you are not confident you can do the original phone problem.
Long distance phone calls cost 1 dollar for anything under 5 minutes for region 1, and $1.50 for anything under 5 minutes for region 2. For a call over 5 minutes for region 1, the charge is $5, and it is $7 for region 2. After 10pm your call will be half price. If you have a preferred card, you will get a $2 credit, or pay nothing if you bill is less than $2. A call over 60 minutes will have a $3 surcharge for both regions.
Make sure you implement this code in steps. First, make sure you can get the inputs. Second, implementing just one of the conditions, say a phone call less than 5 minutes in either region, and get the correct output. Then add another condition.. and so on.. Always have a working program in your back pocket. Also, do NOT add too much code before you try to run the program. That way you will know where the error is.
The original problem was as follows:
Long distance calls cost 20 cents per minute for region 1 for the first 5 minutes, then 5 cents per minute after 5 minutes. For region 2, it is 30 cents per minute for the first 5 minutes and 6 cents per minute after that. If you call starts after 10pm, your call will be half price, for both regions. If you have a preferred calling card, you get a $2 credit for each call (if the call is more then $2). A call over 60 minutes will be assessed a $3 surcharge for both regions. For Holidays, every call is charged at a flat rate of 8 cents per minute for both regions and for any length of call.
|