Thread: Shipping calculator need help

  1. #1
    Registered User
    Join Date
    Feb 2020
    Posts
    1

    Shipping calculator need help

    For my intro to programming class our professor wants us to do this assignment: Global Courier Services will ship your package based
    on how much it weighs and how far you are sending the package.

    You need to write a design tool and a program in C that calculates
    the shipping charge based on weight and distance and the total cost.

    The shipping rates are as follows:

    BASED ON WEIGHT

    Charge 10 dollars for all package weighing 10 pounds or less

    Charge an additional 2 dollars per pound for each pound
    above 10 (make sure you charge the first 10 dollars)

    For example if the weight is 2 pounds then the cost based on
    weight is 10 dollars

    For example if the weight is 55 pounds then the cost based
    on weight is 10 for the first 10 pounds and 80 dollars for
    the extra weight.

    BASED ON DISTANCE
    Charge 5 dollars for each 500 miles or part thereof.

    For example if the distance is 1 foot then the cost based
    on distance is 5 dollars.

    For example if the distance is 1300 miles then the cost
    based on distance is 15 dollars (3 500 segments) based on
    per 500 miles shipped.

    Test samples:
    Pounds 1 27 2222
    Miles 1 2727 373737
    Weight Cost $10.00 $44.00 $4434.00
    Distance Cost $5.00 $30.00 $3740.00
    Total Cost $15..0 $74.00 $8174.00

    Ive got everything worked out except for how to find the distance cost, getting lost there. Here is the code i have so far:
    Code:
    
    
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define PAUSE system("pause")
    
    
    main(){
        
        int weight = 0;
        int miles = 0;
        int weightCost = 10;
        int distanceCost = 0;
        int charge;
        int total = 0;
        
            printf("Enter weight of package: \n");
            scanf("%i", &weight);
            printf("Enter distance: \n");
            scanf("%i", &miles);
        
        if(weight <= 10){
        
            weightCost = 10;
            printf("Weight cost is $%i \n", weightCost);
        }
        else if (weight > 10) {
        
             charge = (weight - 10)*2;
             charge = charge + weightCost;
         
            printf("Weight cost is $%i\n", charge);
        }
        
        if (miles <= 500){
        
            printf("Distance cost is $5\n");
    }
        else if (miles > 500){
        
             //here is where im lost as to how to get $5 per 500 segment
        
            printf("Distance cost is $");
    }
        
    PAUSE;    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    Study what miles / 500 and miles % 500 tell you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shipping calculator problem
    By tlxxxsracer in forum C Programming
    Replies: 1
    Last Post: 02-18-2015, 12:34 AM
  2. WTF! USPS Shipping...
    By holden in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-22-2004, 10:48 AM
  3. Best shipping message ever
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 06-21-2004, 08:11 AM

Tags for this Thread