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:
#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;
}