Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
January 28th, 2003, 07:02 PM
 luvmyroush
Junior Member

Join Date: Jan 2003
Location: NC
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
Breaking Up Calculations

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
January 28th, 2003, 07:54 PM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,534
Time spent in forums: 2 Months 3 Days 4 h 40 m 8 sec
Reputation Power: 4106
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
January 28th, 2003, 07:56 PM
 luvmyroush
Junior Member

Join Date: Jan 2003
Location: NC
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry I'm in the wrong place, but thank you for your help!

#4
January 28th, 2003, 07:58 PM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,534
Time spent in forums: 2 Months 3 Days 4 h 40 m 8 sec
Reputation Power: 4106
Oops! Change gallons to cubic metres in all the above

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Breaking Up Calculations