Write a program for C++ 5. (11 pts) Cost of shipping: Write, compile, and test a
ID: 3587746 • Letter: W
Question
Write a program for C++
5. (11 pts) Cost of shipping: Write, compile, and test a C++ program that uses an if-else structure for problem 3.11 on page 108.
Use the format specified earlier (initial block of comments with TCC logo, name, description, etc.)
Display clear instructions so that the user understands the purpose of the program and what to enter.
When the shipping cost is display, include the symbol ($) and 2 digits after the decimal point.
Run the program for the following 6 cases:
1 weight in each of the valid ranges (4 cases)
1 negative weight (display an appropriate message)
1 weight over 20 lb (not 50 as the text states) with the message indicated in the text
Explanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{
double weight;
cout<<"Enter the weight of the package ";
cin>>weight;
if(weight>0 && weight<1)
cout<<"The shipping cost is $"<< 3.5*weight ;
else if(weight>1 && weight<3)
cout<<"The shipping cost is $"<<5.5*weight;
else if(weight<10 && weight>3)
cout<<"The shipping cost is $"<<8.5*weight;
else if(weight<20 && weight>10)
cout<<"The shipping cost is $"<<10.5*weight;
else if(weight< 0)
cout<<"Enter a valid weight as the weight cannot be negative";
else if(weight >20)
cout<<"The package cannot be shipped;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.