Question

In: Computer Science

Programming 3: Multi-Way Branching Shipping Charges The Fast Freight Shipping Company charges the following rates: Given...

Programming 3: Multi-Way Branching

Shipping Charges

The Fast Freight Shipping Company charges the following rates:

  • Given the Weight of Package (in Kilograms), use the following Rate ($) per 500 Miles Shipped.

  • 2 kg or less = $1.10 per 500 Miles Shipped

  • Over 2 kg but not more than 6 kg = $2.20 per 500 Miles Shipped

  • Over 6 kg but not more than 10 kg = $3.70 per 500 Miles Shipped

  • Over 10 kg but not more than 20 kg = $4.80 per 500 Miles Shipped

Write a program that reads the weight of the package and the distance it is to be shipped, and then displays the charges to two decimal points.

  • Input Validation:
  • Do not accept values of 0 or less for the weight of the package.
    • Print "ILLEGAL WEIGHT: BELOW MINIMUM"
  • Do not accept weights of more than 20 kg (this is the maximum weight the company will ship).
    • Print "ILLEGAL WEIGHT: ABOVE MAXIMUM"
  • Do not accept distances of less than 10 miles or more than 3,000 miles. These are the company’s minimum and maximum shipping distances.
    • Print "ILLEGAL DISTANCE"

I got stuck here:

#include
using namespace std;

int main(){
int i=0,miles;
   double j,weight,cost,distance;

   cin>>weight;
      if(weight<=0){
         cout<< "ILLEGAL WEIGHT: BELOW MINIMUM" << endl;
      }
      else(weight>20){
         cout<< "ILLEGAL WEIGHT: ABOVE MAXIMUM" << endl;
      }
       

   cin>>distance;
      while(distance<10 || distance >3000){
         cout<< "ILLEGAL DISTANCE" << endl;
      }
   i=miles/500;
   j=miles%500;

   if(j>0){
       i=i+1;
   }
   if(weight<=2){
       cost=i*1.10;
   }
   else if(weight>2 && weight<=6){
       cost=i*2.20;
   }
   else if(weight>6 && weight<=10){
       cost=i*3.70;
   }
   else if(weight>10 && weight<=20){
       cost=i*4.80;
   }
   cout<<"Cost of Shipping: " << cost;
   return 0;
}

Random inputs are....

Input : -1 2000

Expected inputs are : ILLEGAL WEIGHT: BELOW MINIMUM

Input: 1 5000

Expected output : ILLEGAL DISTANCE

input: 2 2000

Expected output : 4.40 (<--| enter symbol)

Please revise and let me know what i did wrong.....

Solutions

Expert Solution

Corrected Program

#include<iostream>
#include<iomanip>
using namespace std;

int main(){
    int i=0;
    double j,weight,cost,distance;

    cin>>weight;
      if(weight<=0)
      {
          cout<< "ILLEGAL WEIGHT: BELOW MINIMUM" << endl;
          return 0;
       }
       if(weight>20){
          cout<< "ILLEGAL WEIGHT: ABOVE MAXIMUM" << endl;
          return 0;
       }
    cin>>distance;
       if((distance<10 )||(distance >3000))
    {
          cout<< "ILLEGAL DISTANCE" << endl;
          return 0;
    }
    i=distance/500;
    j=int(distance)%500;

    if(j>0)
    {
        i=i+1;
    }
    i=float(i);
    if(weight<=2){
        cost=i*1.10;
    }
    else if((weight>2) && (weight<=6))
        {

    cost=i*2.20;

    }
    else if((weight>6 )&& (weight<=10)){
        cost=i*3.70;
    }

    else if((weight>10 )&& (weight<=20)){
        cost=i*4.80;
    }
    cout<<"Cost of Shipping: " <<setprecision(2)<< cost;
    return 0;
}


Related Solutions

The Fast Freight Shipping Company charges the followingrates: Weight of Package(kilograms)         Rate per 500 miles shipped 2...
The Fast Freight Shipping Company charges the followingrates: Weight of Package(kilograms)         Rate per 500 miles shipped 2 kg orless                                                   $1.10 Over 2 kg but not more than6kg                   $2.20 Over 6 kg but not more than 10kg                $3.70 Over 10 kg but not more than 20kg              $4.80 Write a program that asks for the weight of the package andthe distance it is to be shipped, and then displays thecharges. Input Validation: Do not accept values of 0 or less for theweight of the package. Do not...
1a) Rodriguez Company purchased merchandise from Emmett Company with freight terms of FOB shipping point. The...
1a) Rodriguez Company purchased merchandise from Emmett Company with freight terms of FOB shipping point. The freight costs will be paid by the a. shipping company. b.   buyer (Rodriguez Company) c. seller (Emmett Company) d.   buyer and the seller. b) Gee Company purchased merchandise inventory with an invoice price of $7,000 and credit terms of 2/10, n/30. What is the net cost of the goods if Gee Company pays within the discount period? a. $6,300 b. $6,440 c. $6,860 d....
(Value of Information): Midwest Freight Inc. (MFI) is a logistics company handling fragile item shipping. MFI...
(Value of Information): Midwest Freight Inc. (MFI) is a logistics company handling fragile item shipping. MFI has received an order with the stipulation that if the item arrives late, MFI will pay $1,000 for each late day. MFI will make $40,000 if the item is delivered on time, but will lose $17,000 if it is defective. MFI can easily deliver the system on time. However, it may, with probability 0.5, be defective. The deficiency can be removed by an adjustment...
this is in excel VB8 Program 3: Long-Distance Calls A long-distance provider charges the following rates...
this is in excel VB8 Program 3: Long-Distance Calls A long-distance provider charges the following rates for telephone calls: Rate Category Rate per Minute Daytime (6:00 A.M. through 5:59 P.M.) $0.07 Evening (6:00 P.M. through 11:59 P.M.) $0.12 Off-Peak (12:00 A.M. through 5:59 A.M.) $0.05 Create an application that allows the user to select a rate category and enter the number of minutes of the call, then displays the charges. Use the following test data to determine if the application...
Company A and B can borrow for a 3-year term at the following rates. While A...
Company A and B can borrow for a 3-year term at the following rates. While A desires fixed rate borrowing, B prefers floating rate borrowing.             Fixed Rate    Floating Rate A         8.5%               LIBOR + 0.5% B         7%                  LIBOR The swap bank currently makes a market for plain vanilla 3-year interest rate swaps at 7.25% - 7.5%. Illustrate how Company A benefits from the use of interest rate swap. Summarize the risks taken by the swap bank in the interest swap...
The following 3 charges are at the following locations: Q1= +20 uC and is located at...
The following 3 charges are at the following locations: Q1= +20 uC and is located at the origin. Q2= +70 uC and is located at x = 10 meters. Q3= -30 uC and is located at y = 4 meters. What is the magnitude of the force on Q1 due to Q2?What are the x and y components for the force on Q1 due to Q2? Be sure to include direction (either with + or - or or in words...
Given the following linear programming model, answer the questions that follow. You are given the result...
Given the following linear programming model, answer the questions that follow. You are given the result of a computer program. The results are Maximize 9 X1 + 12 X2 + 10 X3 Subject to: Machine Constraint:   3 X1 + 4 X2 + 3 X3 < 160 Labor Constraint:        6 X1 + 10 X2 + 4 X3 < 288 Materials Constraint: 2 X1 + 2 X2 + 7 X3 < 200 Product 2 Constraint: X1 < 16 OPTIMAL SOLUTION Objective Function Value...
Given the following linear programming model, answer the questions that follow. You are given the result...
Given the following linear programming model, answer the questions that follow. You are given the result of a computer program. The results are Maximize 9 X1 + 12 X2 + 10 X3 Subject to: Machine Constraint:   3 X1 + 4 X2 + 3 X3 < 160 Labor Constraint:        6 X1 + 10 X2 + 4 X3 < 288 Materials Constraint: 2 X1 + 2 X2 + 7 X3 < 200 Product 2 Constraint: X1 < 16 OPTIMAL SOLUTION Objective Function Value...
Question 3 : A package delivery company is contemplating building a new shipping center. The most...
Question 3 : A package delivery company is contemplating building a new shipping center. The most recent shipping center, 10,000 square feet large, was built in 2005, at a cost of $500,000. The new shipping center will be 15,000 square feet large. Using the power-sizing cost-estimating model, estimate the cost of building a new shipping center now, using the assumptions below to construct a weighted cost index value for 2005 and for today. Use 0.90 for the cost-capacity factor. The...
QUESTION 3 Jay –Ethan Company is a multi-billion pharmaceutical company that has won a contract by...
QUESTION 3 Jay –Ethan Company is a multi-billion pharmaceutical company that has won a contract by the government to produce hand sanitizers and respiratory gadgets for frontline health workers in Bono East region. As a result, the company has decided to give bonuses to its employees to motivate them for the risky task ahead. A sample of the weekly bonus received by the employees is organized in the table below: Weekly Bonus ($) 30<35 35<40 40<45 45<50 50<55 55<60 60<56...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT