8 Replies - 3107 Views - Last Post: 20 October 2009 - 11:07 PM Rate Topic: -----

#1 b33p  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: Equation for calculation of shipping charges..

#2 no2pencil  Icon User is online

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,449
  • Joined: 10-May 07

Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 09:07 PM

** Renamed title to be more descriptive **
Was This Post Helpful? 0
  • +
  • -

#3 xtreampb  Icon User is offline

  • D.I.C Regular

Reputation: 13
  • View blog
  • Posts: 310
  • 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?
Was This Post Helpful? 0
  • +
  • -

#4 b33p  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 .
Was This Post Helpful? 0
  • +
  • -

#5 b33p  Icon User is offline

  • New D.I.C Head

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

Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 09:43 PM

andybody?
Was This Post Helpful? 0
  • +
  • -

#6 b33p  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#7 seeP+  Icon User is offline

  • D.I.C Addict

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

Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 10:18 PM

Post your entire code.

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

Was This Post Helpful? 0
  • +
  • -

#8 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4188
  • View blog
  • Posts: 11,857
  • 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. :)
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil  Icon User is online

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,449
  • Joined: 10-May 07

Re: Equation for calculation of shipping charges..

Posted 20 October 2009 - 11:07 PM

** Topics merged **
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1