#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    NC
    Posts
    2
    Rep Power
    0

    Question 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!!!! :D

    Ashley
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,624
    Rep Power
    4247
    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.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    NC
    Posts
    2
    Rep Power
    0
    Sorry I'm in the wrong place, but thank you for your help!
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,624
    Rep Power
    4247
    Oops! Change gallons to cubic metres in all the above :)

IMN logo majestic logo threadwatch logo seochat tools logo