In: Computer Science
At We Ship Anything, we need to create a program that will calculate the charges associated with the weight of a specific package. We charge a base rate of $54.03 for any package and then add a premium to it based on the package weight. The additional costs are as follows: • If the package weighs less than 2.5 kg then we charge an additional $2.00. • If the package weighs 2.5kg to 5kg then we charge an additional $3.00. • If the package weighs more than 5kg we charge an additional $4.00. Create a program that will ask the user to enter the destination and weight of their package. We will then display the destination, the package weight, the base rate, additional package charge and total charge owing. Display it with each of the values on a separate line
Pseudocode:
Here i am attaching the pseudocode for the given problem. SO that you can execute in any programming language
Code in Python:
# Taking destination and weight from the user
destination = input("Enter Destination: ")
weight = float(input("Enter weight of package: "))
# Initialization of variables
B_rate = 54.03
add_charge = total_charge = 0
# Calculation of additional charge
if weight < 2.5:
add_charge = 2.0
elif weight >=2.5 and weight <=5.0:
add_charge = 3.0
else:
add_charge = 4.0
# Calculating total charge
total_charge = B_rate + add_charge
# Printing the results
print("Destination is: ",destination)
print("Weight is: ",weight)
print("Base rate is: ",B_rate)
print("Additional charge is: ",add_charge)
print("Total charge is: ",total_charge)
OUTPUT:
Code in C language:
# include<stdio.h>
# include<conio.h>
void main()
{
char destination[50];
float weight, B_rate = 54.03, add_charge = 0.0,
total_charge = 0.0;
printf("Enter Destination: ");
scanf("%s",&destination);
printf("Enter package weight: ");
scanf("%f",&weight);
if(weight < 2.5)
{
add_charge = 2.0;
}
else if(weight >= 2.5 && weight <=
5.0)
{
add_charge = 3.0;
}
else
{
add_charge = 4.0;
}
total_charge = B_rate + add_charge;
printf("\nDestination is: %s",destination);
printf("\nWeight is: %.2f",weight);
printf("\nBase rate is: %.2f",B_rate);
printf("\nAdditional Charge is:
%.2f",add_charge);
printf("\nTotal charge is: %.2f",total_charge);
}
OUTPUT: