Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A shipping calculator in C Programming. This is for an entry level C programming class. Modules 1 - 6 have covered basic arithmetic, variables, data

A shipping calculator in C Programming. This is for an entry level C programming class. Modules 1 - 6 have covered basic arithmetic, variables, data types, functions, pointers, if else switch, logical and compound operators, and loops. Only include the stdlib.h and stdio.h.

Here is the assignment.

The charges are based on each 500 miles shipped. The mileage should be in whole numbers. They are not prorated, i.e., 600 miles is the same charge as 900 miles; in other words, 600 and 900 miles is counted as 2 segments of 500 miles each.

Here is the table they gave you:

Package Weight Rate per 500 miles shipped Charge
2 pounds or less $1.50
More than 2 but not more than 6 $3.70
More than 6 but not more than 10 $5.25

Your code needs to validate the input completely, e.g., the weight and mile amounts must be positive. If an input is invalid, e.g., the weight is zero or less, you should display an appropriate, professional error message, e.g., Error: Weight must be greater than zero!, which should be offset and surrounded by white space, so it stands out, and repeat getting that input until valid input is received. Keep in mind, the user will find it annoying if they must enter both the miles and weight at the same time, and only one of them caused an error, or they must reenter already valid data; see the Sample Run. Only if all the input is valid, should the program calculate and display one shipping charge, and pause, but not quit, before proceeding to a new customer.

At this point for the code, you should only solve the problem using what you learned from modules 1 6, i.e., NO arrays, etc. Make sure you divide your program into multiple functions, i.e., each function solves one problem, and main() ties them all together. Also, make sure you follow the Code Conventions and good programming practices, e.g., appropriately initialize variables to zeros, avoid stacked if or if-else constructs unless necessary, dont use break, continue, etc. to get out of a loop, goto, a return statement more than once at the end per function, etc. Your test cases should test the various possibilities, and the limits of the program, which means, you will need to use an appropriate loop, which will ask if you would like to process the next customer or not by asking them to enter an appropriate value. Once there are no more customers to process, the program should display Good-bye! and end.

Hints: You may need to reset any values after you display the answer and before you get the input for the next customer. Big Helpful Hint: For the number of segments formula, you may want to start with integer division, e.g., 1200 miles / 500 miles per segment = 2 segments, and then, expand on that. What do you need to do to the calculation to get the correct number of segments, e.g., > 1 to 500 is 1 segment, 501 to 1000 is 2 segments, 1001 to 1500 is 3 segments, etc. You cannot solve this one with nested if-else constructs; try, pattern analysis.

You should be able to solve this problem with only one loop. Although you can easily solve this with multiple nested loops, the challenge is to solve it using one loop; see the following Sample Run.

Sample Run

Enter the number of miles as a whole number: 0

Error: Miles must be greater than zero!

Enter the number of miles as a whole number: 1

Enter the weight of the package in pounds: 0

Error: Weight must be greater than zero!

Enter the weight of the package in pounds: 1

The cost to ship your package is: $1.50.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 2

The cost to ship your package is: $1.50.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 2.1

The cost to ship your package is: $3.70.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 6

The cost to ship your package is: $3.70.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 10.1

Error: We don't ship packages over 10 pounds!

Enter the weight of the package in pounds: 10

The cost to ship your package is: $5.25.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 501

Enter the weight of the package in pounds: 3.75

The cost to ship your package is: $7.40.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 1000

Enter the weight of the package in pounds: 6.1

The cost to ship your package is: $10.50.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 12450

Enter the weight of the package in pounds: 1

The cost to ship your package is: $37.50.

Enter 1 to continue or 0 to quit: 0

Good-bye!

Press any key to continue . . .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions