Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Fast Freight Shipping company charges the following rates: Weight of package (in kilograms) Rate per 500 miles shipped 2 kg or less $1.10 Over
The Fast Freight Shipping company charges the following rates:
Weight of package (in kilograms) Rate per 500 miles shipped
2 kg or less $1.10
Over 2 kg but not more than 6 kg $2.20
Over 6 kg but not more than 10 kg $3.70
Over 10 kg but not more than 20 kg $4.80
Write a program that asks for the weight of the package and the distance to be shipped, then displays the charges.
Note: To calculate the charges, the distance is rounded up to the next higher multiple of 500 miles. For example, a distance of 510 miles is rounded up to 1,000 miles, or 2 times 500 miles. If the package weights say 1kg, the charge will be $1.10 times 2, that is $2.20. If the package weights 5.5 kg, the charge will be $2.20 times 2, that is $4.40. A distance which is an integral multiple of 500 miles, say 2,000 miles, is not rounded up. If the distance is 2,000 miles and the weight is 3 kg, the charge will be $2.20 times 4, that is $8.80.
1. Additional requirements Make sure you meet all the requirements to avoid losing points
Make sure you follow the requirements in the Homework Notes.
Pseudocode of main function
-Prompt user to input weight
-Validate input. A weight is valid if it is > 0 and
-Prompt user to input distance
-Validate input. A distance is valid if it is >= 10 miles and
-Calculate shipping charges
-Print the charges
The shipping charges are displayed with a decimal point and two digits after the decimal point
2. Implementation hint
To round up a distance to the next higher multiple of 500 miles, you can use this formula:
roundedMultiple = ((distance - 1) / 500) + 1;
For example, if distance is 510 miles, it is rounded up to 2 times 500 miles, and roundedMultiple will be equal to 2. If distance is 1500 miles, it is equal to 3 times 500 miles, and not rounded up, and roundedMultiple will be equal to 3. Note roundedMultiple should be declared an int. You may assume the distance has no fractional part.
3. Grading criteria
Source code inspection (grader)
*Style (refer to "Homework Notes"): 4 points
Program compilation and execution (zyLabs or grader)
*Weight input validation: 20 points (test cases 1, 2 shown below, 10 points each)
*Distance input validation: 20 points (test cases 3, 4 shown below, 10 points each)
*Charges calculation and display: 56 points (test cases 5 through 12 shown below, 7 points each
This is my code but it's not correct and keeps looping
#include
using namespace std;
int main()
{
//Declare variables
double weight, charges;
int distance;
//prompt and read the input as weight of the package
//from the user
cout
cin >> weight;
//Input validation
while (weight 20)
{
cout
cout
cout
cin >> weight;
}
//Prompt and read the input as distance from the user
cout
cin >> distance;
//Input validation
while (distance 3000)
{
cout
cout
cout
cin >> distance;
}
distance = (distance + 499) / 500;
//If the weight of the package is 2kg or less, then
//calculate the total charges by using rate is 1.10
if (weight
charges = distance * 1.10;
//If the weight of the package is over 2kg, but not
//more than 6kg, then calculate the total charges by
//using rate is 2.20
else if (weight > 2 && weight
charges = distance*2.20;
//If the weight of the package is over 6kg, but not
//more than 6kg, then calculate the total charges by
//using rate is 3.70
else if (weight > 6 && weight
charges = distance*3.70;
//If the weight of the package is over 10kg, but not
//more than 20kg, then calculate the total charges by
//using rate is 4.80
else if (weight > 10 && weight
enerated too much output. stricted to 50000 characters. gram for any unterminated loops generating output. input 21 Enter the weight of the package (in kilogzama) : Invalid weight provided. ght shoul be greater than 0 kgand less than 20 kg Re enter less than 20 kg enter The weight should be greater chan k and less than 20 kg. Renter The weight should be greater than 0 kg and less than 20 kg. Re enter The weight should be greater chan o kg and less than 20 kg. Re enter The weight should be greater than o kg and less than 20 kg. Re enter The weight should be gzeater than 0 kg and less than 20 kg- Re enter The veight should be greater than 0 kg and less than 20 kg. Re enter The weight should be greater than 0 kg and less than 20 g Re ente The weight should be greater than 0 kg and 1 The weight should be greater than 0 kg and less than 20 kg.Re onter The weight should be greater than 0 kg and less than 20 kg. Reenter The weight should be greater than 0 kg and less than 20 kg. Re enter The weight should be greater than 0 kg and less than 20 kg. Re onter The veight should be greater than 0 kg and Less than 20 kg ess than 20 kg. Re enter . Re enter no sc delete 5 6 7 8 9 O P charges = distance* 4.80;
//Display output
cout
return 0;
}
Expected output
Expected output
Expected output
Expected output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started