/* This is the eighth lab of Lab EE107
The purpose of this lab understand how a program (using the switch case) that checks a freight cost
and print out the result.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: March 19th, 2024.
*/
#include <stdio.h>

int main() {
    float p_EU; // Basic freight rate per ton of goods per kilometer
    float w_EU; // Weight of the goods
    float s_EU; // Distance
    float d_EU; // Discount
    float f_EU; // Total freight

    // Prompt the user to input parameters
    printf("Enter the basic freight rate per ton of goods per kilometer (p): ");
    scanf("%f", &p_EU);
    printf("%.2f\n", p_EU);

    printf("Enter the weight of the goods (w in tons):");
    scanf("%f", &w_EU);
    printf("%.2f \n", w_EU);

    printf("Enter the distance (s in kilometers): ");
    scanf("%f", &s_EU);
    printf("%.2f\n", s_EU);

    // Calculate the discount based on the given conditions
    switch ((int)s_EU / 500) {
        case 0:
            d_EU = 0;
            break;
        case 1:
            d_EU = 0.02;
            break;
        case 2:
            d_EU = 0.05;
            break;
        case 3:
            d_EU = 0.08;
            break;
        case 4:
            d_EU = 0.10;
            break;
        default:
            d_EU = 0.15;
            break;
    }

    // Calculate the total freight
    f_EU = p_EU * w_EU * s_EU * (1 - d_EU);

    // Display the total freight
    printf("Total freight: %.2f\n", f_EU);

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: