Create a program that determine the shipping cost for an order based on the following table:
From To Price
$0.00 $19.99 $2.95
$20.00 $49.99 $3.95
$50.00 $79.99 $4.95
$75.00 $1000.00 Free
From To Price
$0.00 $19.99 $2.95
$20.00 $49.99 $3.95
$50.00 $79.99 $4.95
$75.00 $1000.00 Free
Sure! Here's a step-by-step breakdown of how you can create a program to determine the shipping cost based on the given table:
Step 1: Define the table data
- Start by creating a data structure to store the shipping costs based on the price ranges.
- You can use a dictionary or a list of tuples to represent the table data.
Step 2: Get the order total from the user
- Prompt the user to enter the total amount of their order.
- Make sure to validate the input to ensure it's a valid number.
Step 3: Determine the shipping cost
- Use an if-elif-else statement to compare the order total with the price ranges in the table.
- Based on the order total, assign the corresponding shipping cost to a variable.
Step 4: Display the shipping cost
- Print the shipping cost to the console or display it back to the user.
Here's an example implementation in Python:
```python
# Step 1: Define the table data
shipping_costs = [
(0.00, 19.99, 2.95),
(20.00, 49.99, 3.95),
(50.00, 79.99, 4.95),
(75.00, 1000.00, 0.00)
]
# Step 2: Get the order total
order_total = float(input("Enter the total amount of your order: "))
# Step 3: Determine the shipping cost
shipping_cost = None
for low, high, cost in shipping_costs:
if low <= order_total <= high:
shipping_cost = cost
break
# Step 4: Display the shipping cost
if shipping_cost is None:
print("Invalid order total")
else:
print("Shipping cost:", shipping_cost)
```
Note: This is just one way to implement the program. You can modify it based on your specific requirements or programming language of choice.
Sure! Here's a Python program that determines the shipping cost for an order based on the table you provided:
```python
def calculate_shipping_cost(order_amount):
if order_amount < 20:
return 2.95
elif order_amount < 50:
return 3.95
elif order_amount < 80:
return 4.95
else:
return 0.00
order_amount = float(input("Enter the order amount: $"))
shipping_cost = calculate_shipping_cost(order_amount)
print("The shipping cost for this order is: $" + str(shipping_cost))
```
To use this program, you can simply run it and input the order amount when prompted. The program will then calculate and display the shipping cost for that order.
Here's a breakdown of how the program works:
- The `calculate_shipping_cost()` function takes the `order_amount` as input and uses if-elif-else statements to determine the appropriate shipping cost based on the table you provided.
- The `order_amount` is taken as user input using the `input()` function. It is then converted to a float using the `float()` function to ensure proper comparison.
- The `calculate_shipping_cost()` function is called with the `order_amount`, and the resulting shipping cost is stored in the variable `shipping_cost`.
- Finally, the shipping cost is displayed to the user using the `print()` function.
I hope this helps! Let me know if you have any further questions.