Question

In C using (printf and scanf) Write a program to ask the user for the weight...

In C using (printf and scanf)

Write a program to ask the user for the weight of a package, and display the shipping charges for the package. If the weight of the package is less than or equal to 0 pounds, inform the user and exit the program. The shipping charges are:

Weight of Package Shipping Charge
2 pounds or less $1.25
Over 2 pounds but not more than 6 pounds $2.50
Over 6 pounds but not more than 10 pounds $3.90
Over 10 pounds $4.40

Create constants for the cutoff values of 2.0, 6.0, and 10.0, the value of 0.0, and for the 4 shipping charges.

Example Run #1:
(bold type is what is entered by the user)

Enter the weight of the package: 2.0

The shipping charge is $x.xx.

Example Run #2:

Enter the weight of the package: 0
The weight of the package must be greater than 0.00.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include <stdlib.h>
main()
{
   float Weight;
   const float a=0;
   const float b=2;                    
   const float c=6;
   const float d=10;
  
   printf("Enter the weight of the package:");
   scanf("%f",&Weight);         //Taking weight of package as input from user
   if(Weight<a)
   {
   printf("The weight of the package must be greater than 0.00.");
   exit(0);
   }
   else if(Weight<=b)
   {
       printf("The shipping charge is:$1.25");
   }
   else if(Weight>b&&Weight<=c)
   {
   printf("The shipping charge is:$2.50");
   }
   else if(Weight>c&&Weight<=d)
   {
   printf("The shipping charge is:$3.90");
   }
   else
   {
   printf("The shipping charge is: $4.40 ");
   }
  
}

thankyou

Add a comment
Know the answer?
Add Answer to:
In C using (printf and scanf) Write a program to ask the user for the weight...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • Please help me with this program. Using C++ (printf & scanf) statements. Thank you. ASSIGNMENT: Write...

    Please help me with this program. Using C++ (printf & scanf) statements. Thank you. ASSIGNMENT: Write a program to ask the user for a number that includes a decimal point. Then display the integer part of the number (the part of the number to the left of the decimal point) and the decimal part of the number (the part of the number to the right of the decimal point, including the decimal point Follow the 3 steps in the Information...

  • The Fast Freight Shipping Company charges the following rates: Weight of Package Rate per Pound 2...

    The Fast Freight Shipping Company charges the following rates: Weight of Package Rate per Pound 2 pounds or less $1.50 Over 2 pounds but not more than 6 pounds $3.00 Over 6 pounds but not more than 10 pounds $4.00 Over 10 pounds $4.75 Write a program that asks the user to enter the weight of a package then displays the shipping charges.

  • In this assignment, you will develop a C++ program which calculates a shipping charge and determines...

    In this assignment, you will develop a C++ program which calculates a shipping charge and determines the “type of trip” for a freight shipping company. Ask the user to enter the distance a package is to be shipped, and use a menu and a switch statement to determine the rate based on the package’s weight. Then display the shipping charge and using the table in #7 below, display the type of trip. Below is the chart to use to calculate...

  • Can someone complete this program for me in c programming language? Thank you! The Send-Ex Shipping...

    Can someone complete this program for me in c programming language? Thank you! The Send-Ex Shipping Company charges the following rates: Weight of Package 2 lbs or less Over 2 lbs but no more than 6 lbs Over 6 lbs but no more than 10 lbs Over 10 lbs Rate per Pound $1.10 $2.20 $3.70 $4.10 Write a program that asks the user to enter the weight of a package and then displays the total shipping charge. Reserve Point Opportunity/...

  • Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players...

    Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players to play a game of tic-tac-toc. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should...

  • Hospital Charges ASSIGNMENT: Write a program to calculate and display the amount of the charges for...

    Hospital Charges ASSIGNMENT: Write a program to calculate and display the amount of the charges for a hospital stay. Create a global constant for the daily fee of a hospital room ($350.00/day). Ask the user for: The number of days spent in the hospital The amount of the medication charges The amount of the surgical charges The amount of the lab fees The amount of the physical rehabilitation charges Then, using functions, calculate the stay charges (number of days *...

  • Answer in C using basic C and loops. ASSIGNMENT: Write a program that will display how...

    Answer in C using basic C and loops. ASSIGNMENT: Write a program that will display how many times a ball will bounce until its height is less than 1 inch. A ball has a property called the coefficient of restitution, a number between 0.0 and 1.0, that indicates how 'bouncy' the ball is. A coefficient of restitution of .5 means that the ball will bounce-up 50% of its initial height after each bounce Write a program to ask the user...

  • C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you...

    C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you may discuss ideas with your classmates, etc., everyone must write and submit their own version of the program. Do NOT use anyone else’s code, as this will result in a zero for you and the other person! Shipping Calculator Speedy Shipping Company will ship your package based on the weight and how far you are sending the package, which can be anywhere in the...

  • C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for...

    C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the following restrictions: Shipping requirements The package weight must not exceed 50 pounds. The package must not exceed 3 feet in length, width, or height. The girth of the package must not exceed 5 feet. The girth is the circumference around the two smallest sides of the package. If side1, side2, and side3 are the lengths of the three sides, and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT