00 miles, we'll ship that as well but we will charge for a full 500 miles. But if the distance is less than zero, set the distance to zero (which is really 500) and charge the user accordingly. This means that we will in fact ship your package less than ten miles (which differs from what the textbook says) but we will charge you quite a bit for that. We charge by the mile, so accept distances that are not multiples of 500 (e.g. 650 miles) and compute the fee accordingly (more than the cost for 500 miles, but le
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
C++
Accept a package weight of zero; we'll ship it! If the user enters a weight that is less than zero, set it at zero instead. Do not display an error.
If the distance is less than 500 miles, we'll ship that as well but we will charge for a full 500 miles. But if the distance is less than zero, set the distance to zero (which is really 500) and charge the user accordingly. This means that we will in fact ship your package less than ten miles (which differs from what the textbook says) but we will charge you quite a bit for that.
We charge by the mile, so accept distances that are not multiples of 500 (e.g. 650 miles) and compute the fee accordingly (more than the cost for 500 miles, but less than for 1000). Fractions of miles are allowed so bring that input in as a double.
For your screen shot, enter a package weight of 12.5 kg to be shipped 1310.5 miles. As always for money, the shipping charge should show exactly two digits after the decimal point. For parameters that are out of bounds (too far or too heavy) display an error message.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images