Create the following program in C++ A shipping company calculates charges based
ID: 3858858 • Letter: C
Question
Create the following program in C++
A shipping company calculates charges based on parcel's weight and distance to be shipped. The weight charges are: 0 to 10 pounds - > $0.75 per pound 10 to 15 pounds - > $0.85 per pound 15 to 20 pounds - > $0.95 per pound over 20 pounds NOT ALLOWED Distance charges are: 0 to 50 miles - > $0.07 per mile 50 to 100 miles - > $0.06 per mile 100 to 200 miles - > $0.05 per mile 200 to 500 miles - > $0.04 per mile over 500 miles NOT ALLOWED Create a program proj2_l.cpp to compute the total charge based on the two schedules above. Your program should ask the user for the parcel's weight and distance to be shipped. Then it should compute and add the two charges into the final one to be displayed. IMPORTANT: Your program should display an ERROR for values that are not allowed for either weight and/or miles. Not allowed values are negative or over the limit from the two schedules. Input validation should use loops (page 250). Sample run: Welcome to Cristian's Shipping Company! Please enter the weight in pounds of your package: 2.5 Please enter the distance in miles to be shipped: 56 Your total charge is: $5.24 The total is computed as follows: [2.5 * 0.75 + 56 * 0.06], where of course the weight and miles are variables and not numbers.Explanation / Answer
//Please see the below code please do thumbs up if you like the solution
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double weight,distance;
double total_charge=0;
cout << "Welcome to Cristian's Shipping Company!"<<endl;
cout << "Please enter the weight in pounds of your package: ";
cin>>weight;
if (weight > 20)
{
cout << "weight over 20 pounds are NOT ALLOWED";
return 0;
}
cout << "Please enter the distance in miles to be shipped: ";
cin>>distance;
if (distance > 500)
{
cout << "Distance over 500 miles NOT ALLOWED";
return 0;
}
if (weight > 0 && weight <= 10)
total_charge += (weight * 0.75);
else if (weight > 10 && weight <= 15)
total_charge += (weight * 0.85);
else if (weight > 15 && weight <= 20)
total_charge += (weight * 0.95);
if (distance > 0 && distance <= 50)
total_charge += (distance * 0.07);
else if (distance > 50 && distance <= 100)
total_charge += (distance * 0.06);
else if (distance > 100 && distance <= 200)
total_charge += (distance * 0.05);
else if (distance > 200 && distance <= 500)
total_charge += (distance * 0.04);
total_charge=ceil(total_charge*100)/100;
cout<<"Your total charge is $"<<total_charge;
return 0;
}
OUTPUT:
Welcome to Cristian's Shipping Company!
Please enter the weight in pounds of your package: 2.5
Please enter the distance in miles to be shipped: 56
Your total charge is $5.24
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.