Write a C program that calculates the cost of transporting a
Solution
#include <stdio.h>
int main()
 {
 char ch;
 double weight;
 double cost = 0;
 printf(\"Enter the passenger class (E for Economy, B for Business, V for VIP): \");
 scanf(\"%c\", &ch);
 printf(\"Enter the luggage weight: \");
 scanf(\"%lf\", &weight);
   
 if(ch == \'E\'){
 if( weight <= 25){
 cost = 0;
 }
 else if(weight > 25 && weight <=40 ){
 cost = 1.5 * (weight - 25);
   
 }
 else {
 cost = (weight - 40) * 2;
 weight = 40;
 cost =cost + 1.5 * (weight - 25);
 }
 printf(\"Total cost is $%lf\ \", cost);
 }
 else if(ch == \'B\'){
 if( weight <= 35){
 cost = 0;
 }
 else if(weight > 35 && weight <=50 ){
 cost = 1.25 * (weight - 35);
   
 }
 else {
 cost = (weight - 50) * 1.5;
 weight = 50;
 cost =cost + 1.25 * (weight - 35);
 }
 printf(\"Total cost is $%lf\ \", cost);
 }
 else if(ch == \'V\'){
 if( weight <= 60){
 cost = 0;
 }
 else {
 cost =30;
 }
 printf(\"Total cost is $%lf\ \", cost);
 }
 else{
 printf(\"Wrong passenger class\ \");
 }
   
   
   
 return 0;
 }
Output:
sh-4.2$ gcc -o main *.c
sh-4.2$ main
Enter the passenger class (E for Economy, B for Business, V for VIP): B
Enter the luggage weight: 39
Total cost is $5.000000
sh-4.2$ main
Enter the passenger class (E for Economy, B for Business, V for VIP): E
Enter the luggage weight: 43.5
Total cost is $29.500000


