c++ crew

Discussion in 'OT Technology' started by CaracicatriZ, Feb 8, 2007.

  1. CaracicatriZ

    CaracicatriZ this fucking guy OT Supporter

    Joined:
    Sep 25, 2005
    Messages:
    1,366
    Likes Received:
    0
    Location:
    Houston - Texas
    [FONT=&quot]This is my assignment:
    [/FONT]
    [FONT=&quot]
    [/FONT]
    [FONT=&quot]Write a program to compute the charge for mailing a series of packages. The charge for a package is based on its weight and volume. There is a charge of $4.00 per pound for the first 2 pounds of package weight, $3.00 per pound for each pound between 2 and 6 and $2.00 per pound for the package weight over 6 pounds. There is no additional charge for a package whose volume is 2000 cubic inches or less. There is an additional charge of $0.01 per cubic inch of package volume over 2000 cubic inches. For example if a package weighs 13.2 pounds and has a volume of 3000 cubic inches then the charge is 4.0*2.00 + 3.0*4.00 + 2.00*7.2 = $34.40 for the weight. Then because the volume is over 2000 cubic inches an additional 1000*0.01 = $10.00 would be added to the charge giving $44.40. There is a minimum charge of $6.00 so if the charge for a package computes to be less than $6.00 it is still charged as $6.00.The program must also compute the total number, weight, volume and charges for the packages. The complete interactive I/O for this program should look exactly like the following:[/FONT]
    [FONT=&quot] [/FONT]
    ------------------------------------------------------
    Enter package weight in pounds (-1.0 to end): 5.0
    Enter package dimensions in inches: 10 10 15
    Charge = $17.00
    ------------------------------------------------------
    Enter package weight in pounds (-1.0 to end): 13.2
    Enter package dimensions in inches: 30 10 10
    Charge = $44.40
    ------------------------------------------------------
    Enter package weight in pounds (-1.0 to end): 1.0
    Enter package dimensions in inches: 6 12 8
    Charge = $6.00
    ------------------------------------------------------
    Enter package weight in pounds (-1.0 to end): -1.0

    Totals for all Packages Processed
    Number Weight Volume Charges
    3 19.2 5076 67.40
    [FONT=&quot] [/FONT]
    [FONT=&quot]basically i have written most of it but i am wondering how to get the loop working properly and have the values add themselves at the end.[/FONT]
    [FONT=&quot]int main ()
    { int num =0;
    double weight, length, width, height, wcharge, scharge, scharge2, size, charge;


    cout<<"Enter package weight in pounds (-1.0 to end): ";
    cin>>weight;
    ++num;
    while (weight != -1)
    {
    if (weight <= 2)
    {wcharge = 4 * weight;}

    else if ((weight > 2) && (weight <= 6))

    {wcharge = 8 + (weight - 2)*3;}

    else if (weight > 6)
    {wcharge = 20 + (weight - 6) * 2;}
    ++weight;

    cout<<"Enter package dimensions in inches: ";
    cin>>length>>width>>height;
    size=length*width*height;
    ++size;
    if (size<=2000)
    { scharge=0;

    charge= wcharge + scharge;
    cout<<" Charge = $"<<charge<<endl;

    }
    if (size>2000)
    {
    scharge = size-2000;
    scharge2 = scharge * .01;
    charge= wcharge + scharge2;

    cout<<" Charge = $"<<charge<<endl;
    }

    ++charge;
    cout<<"Enter package weight in pounds (-1.0 to end): ";
    cin>>weight;
    ++weight;



    }
    cout<<"Totals for all Packages Processed"<<endl;
    cout<<"Number Weight Volume Charges "<<endl;
    cout<<num<<" "<<weight<<" "<<size<<" "<<charge<<endl;


    return 0;
    [/FONT]

    [FONT=&quot][/FONT]

    [FONT=&quot][/FONT]

    [FONT=&quot][/FONT]
    [FONT=&quot]anyone?
    [/FONT]

    [FONT=&quot][/FONT]
    [FONT=&quot]
    [/FONT]
     
  2. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    use the code tags please
     
  3. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    Explain what isn't working properly.
    Values don't add themselves. You need more variables to keep track of running totals. After you complete a set of calculations, add the results you're interested in to the running totals and display the totals when you're done.
     
  4. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,206
    Likes Received:
    517
    Add a couple variables to your declarations (how are you keeping track of the running totals?) and take a closer look at all the increments you have. You don't need most of them.

    I made a couple minor changes to yours and made it work.
     

Share This Page