# Calculation Troubles

• 01-25-2003
ashley21
Calculation Troubles
I have to take a 4-digit number and calculate it 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

Soo, for the number 203, it would calculate \$10.83. Ok, I've set it up numerous ways, and can't get anywhere near the correct price. :confused: Basically what I need to know is -- How can I break up one number into those 4 different calculations?
• 01-25-2003
joshdick
Ever heard of ifs? Sounds like they'd come in handy here.
• 01-25-2003
PJYelton
Loops would be another option. But you need to show us what you got before we can go into any more detail :D
• 01-25-2003
ashley21
I'll attach what I've already got. Keep in mind I'm very new to this, hehehe. Thanks for the help so far. :)
• 01-25-2003
ashley21
I tried doing this for the calculations, but my numbers are still off by a few dollars.

cost1 = gasused%10 * 5.00;
cost2 = (gasused/10)%10 * 0.05;
cost3 = (gasused/10/10)%10 * 0.025;
cost4 = (gasused/10/10/10)%10 * 0.015;
totalcharges = cost1 + cost2 + cost3 + cost4;
• 01-25-2003
Jeremy G
This was fun:

PHP Code:

``` #include <iostream.h> #include <windows.h> #include <stdio.h> /* RULES: 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 */ int main()  {     int number;     float total = 5.0f;     float price;     printf("Enter cubic meters:\n");     cin >> number;     if( number <= 70 ) {         printf("Total price: \$%f.\n", total);         return 0;     } else if( number <= 170 )          price = 0.05f;     else if( number < 400 )         price = 0.025f;     else if( number > 400 )         price = 0.015f;              total += price * number;     printf("The total price is: \$%f.", total  );     return 0; }  ```
• 01-25-2003
ashley21
I'm glad you thought it was fun. :p Thanks for the help!