shipping program trouble

well i finally decided to try out this site, for the reason of my problem.
i don't understand why my code is not working properly every thing looks to be in place, i could use some help : (

#include<iostream>
#include<iomanip>
using namespace std;
int main ()

{

double weight,miles,total;

cout << "Welcom to fast-A$$ shiping" <<endl;
cout << "Please enter the weight then miles you wish ship:";
cin >> weight;
cout << "now miles ";
cin >> miles;

cout << setprecision(2) << fixed << showpoint;

if (miles >= 3000)
{
cout <<"you dont know anyone that far away " <<endl;
return 0;
}

if (miles <= 10)
{
cout <<"well if its that close why dont you walk?" <<endl;
return 0;
}

if (weight <= 0)
{
cout <<"we dont ship one half sheet of paper, sorry " <<endl;
return 0;
}

if (weight <= 2)
{
total = 500 / miles * 1.10;
cout <<"your cost for delivery is:$"<< total <<endl;
return 0;
}

if (weight <= 6)
{
total = 500 / miles * 2.20;
cout <<"your cost for delivery is:$"<< total <<endl;
return 0;
}

if (weight <= 10)
{
total = 500 / miles * 3.70;
cout <<"your cost for delivery is:$"<< total <<endl;
return 0;
}

if (weight >= 20)
{
total = 500 / miles * 4.80;
cout <<"your cost for delivery is:$"<< total <<endl;
return 0;
}

if (weight <= 21)
{
cout <<"sorry your mail is to heavy"<< total <<endl;
return 0;
}

return 0;

}
You mean you have wrong results?
Try to use parenthesis when you calculate total so you can be sure it is what you want and not wrong calculation
500 / miles * 1.10

Might be:
(500 / miles) * 1.10
or
500 / (miles * 1.10)

Hope this help
should be if (weight <= 20) and if (weight >= 21)
won't it be better with if...else if....else statements?
Actually as I see, it has to be with if...else statements.
Because a number less than 2 is less than 6, less than 10 and so on.
So you have to use if...else to calculate only for one of those.
not neccessarily. Notice in the end of each of his if statements he returns.
This will skip all the rest of the if statments or any code following for that matter. it returns out of the function call, or if used in main, exits out of the program completely.
You are right...
I didn't notice it when I read it before. Nice catch :-)
well i tried out the program and its acting odd its should work like this every 500 miles it ads money on to the delivery but it does not work instated, the farther you go and the more weight the delivery is the less it cost, to ship a 10 pound box 44 miles cost $10.00 but to send a 3 pound box 2000 miles its like $1.50 how do i turn this around?
Your math is wrong.

500 / miles (the higher miles gets, the less it'll cost).

You need to work out how many "500" mile lots the truck has to cover. Increment this by 1 to include 0->500. Then multiply that amount by the cost.

e.g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
#include<iomanip>
using namespace std;
int main ()

{

double weight,miles,total;

cout << "Welcom to fast-A$$ shiping" <<endl;
cout << "Please enter the weight then miles you wish ship:";
cin >> weight;
cout << "now miles ";
cin >> miles;

cout << setprecision(2) << fixed << showpoint;

  if (weight <= 6)
 {
  int multiplier = (int)(miles / 500) + 1; // +1 because <500 counts;
  cout << "Multiplier = " << multiplier << endl;
  total = multiplier * 2.20;
  cout <<"your cost for delivery is:$"<< total <<endl;
 }

return 0;
}


Edit: Damn spelling =\
Last edited on
On my system the 10 pound box would cost $42.05
By the way the further the distance the smaller the calculation 500/miles will become.
so for 2000 miles - 500/2000 = 0.25 so that 3 pound box will cost

0.25 * $2.2 which is 55 cents. ($0.55).

So for any given weight the further you ship it the cheaper it becomes.

(Those figures are calculated from the code you posted)
Topic archived. No new replies allowed.