# Equation for calculation of shipping charges..

Page 1 of 1

## 8 Replies - 13314 Views - Last Post: 20 October 2009 - 11:07 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=133376&amp;s=6c932ee8f2b52d6b57f1bdebcd2796cd&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 b33p

Reputation: 0
• Posts: 15
• Joined: 08-September 09

# Equation for calculation of shipping charges..

Posted 20 October 2009 - 09:01 PM

Hi guys, I am suppose to write a program like this but I am stuck can you guys please help?

I am suppose to..
Write a program that asks for the weight of the package and the distance it is to be shipped and then displays the charges.

weight of package in kg rates per 500 miles shipped
2 kg or less \$1.10
over 2kg but not more than 6kg \$2.20
over 6kg but not more than 10 kg \$3.70
over 10kg but not more than 20 kg \$4.80

so far i have this...and when i compiled it it is all wrong..

```#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
float weight, distance, rate;
cout << "Enter the weight of the package.";
cin >> weight;
cout << "Enter the distance to be shipped.";
cin >> distance;

if ( weight <= 2kg )
rate = \$1.10;
if ( weight > 2kg && weight < 6kg )
rate = \$2.20;
if ( weight > 6kg && weight < 10kg )
rate = \$3.70;
if ( weight > 10kg && weight < 20 kg )
rate = \$4.80;

```

** Edit **

Is This A Good Question/Topic? 0

## Replies To: Equation for calculation of shipping charges..

### #2 no2pencil

• Professor Snuggly Pants

Reputation: 6627
• Posts: 30,868
• Joined: 10-May 07

## Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 09:07 PM

** Renamed title to be more descriptive **

### #3 xtreampb

• D.I.C Regular

Reputation: 14
• Posts: 343
• Joined: 20-June 07

## Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 09:08 PM

ok now don't forget the '/' in the /code tag.

Some more details would be great. What do you mean 'it is all wrong' what errors are you getting. from what i can tell, you are not doing any math, just assign vars, but not manipulating them or displaying them on the screen. so what is going on?

### #4 b33p

Reputation: 0
• Posts: 15
• Joined: 08-September 09

## Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 09:13 PM

well right now i just need help on basically where to start because I absolutely have no idea where to start .

### #5 b33p

Reputation: 0
• Posts: 15
• Joined: 08-September 09

## Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 09:43 PM

andybody?

### #6 b33p

Reputation: 0
• Posts: 15
• Joined: 08-September 09

## Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 10:15 PM

Hi guys im stuck on writing an equation for the shipping charge..
i have to write an equation for the shipping charge of an item being shipped for user input miles, and the rate is 2.20 per 500 miles shipped.

i dont know how to make it so my program will know how many whole or segment 500 miles the user has entered. For example if the user entered 2500, that would be 500 x 2.20, but i dont know how to write an equation for it.

The directions does tell me that "when calculating the rate, drop fractions of miles, then add one for each whole or partial segment of 500 miles...but i dont know what this means.

### #7 seeP+

Reputation: 55
• Posts: 601
• Joined: 20-July 09

## Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 10:18 PM

This post has been edited by seeP+: 20 October 2009 - 10:22 PM

### #8 Martyr2

• Programming Theoretician

Reputation: 5187
• Posts: 13,917
• Joined: 18-April 07

## Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 11:02 PM

Actually, it would be 5 x 2.20, not 500. And the way you can figure this out is take the total pounds the user entered and do INTEGER DIVISION on it. This will give you the whole times it can be divided.... for instance if the user enters 1234 and you take that and integer divide it by 500 you will get 2. You could also simply take 1234 / 500 and then drop the decimals (cast the double to an integer). If you also need to calculate the remainder (the decimal parts), you can get that by using modulus... 1234 % 500 = 234 and with that 234 you can integer divide it further.

Its just like the change program if you ever did that one. How many quarters are in 1.28? Number of quarters = (int) (1.28 / .25) and to get the three extra cents would be 1.28 % .25.

Hope you get the idea.

### #9 no2pencil

• Professor Snuggly Pants

Reputation: 6627
• Posts: 30,868
• Joined: 10-May 07

## Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 11:07 PM

** Topics merged **