|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I have a problem where a number (example: 203 cubic meters) needs to be broken up into different prices, like this:
First 70 cubic meters - $5.00 minimum cost Next 100 cubic meters - 5.0 cents per cubic meter Next 230 cubic meters - 2.5 cents per cubic meter Above 400 cubic meters - 1.5 cents per cubic meter The total charges for 203 cubic meters would be $10.83. For my calculations, I have: cost1 = (gasused/70) * 5.00; cost2 = (gasused/100) * 0.05; cost3 = (gasused/230) * 0.025; cost4 = (gasused/400) * 0.015; totalcharges = cost1 + cost2 + cost3 + cost4; My answer doesn't come out correctly. If anyone has any hints or suggestions, you would make me very, very happy!!!! Ashley |
|
#2
|
||||
|
||||
|
This should really be in the algorithms forum IMHO, but I'll bite and help you solve your homework. The main problem I see off hand is your formula. IMHO, it should be:
cost1 = (volume below 70 cubic metres * 5.00 / 70) cost2 = (volume between 71 and 170 gallons) * 0.05 cost3 = (volume between 171 and 400 gallons) * 0.025 cost4 = (volume greater than 400 gallons) * 0.015 I did code the above logic in C (since this is a C forum after all) to test out my theory and obtained $10.825 for 203 cubic metres. |
|
#3
|
|||
|
|||
|
Sorry I'm in the wrong place, but thank you for your help!
|
|
#4
|
||||
|
||||
|
Oops! Change gallons to cubic metres in all the above
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Breaking Up Calculations |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|