View Single Post
Old 09-28-2005, 02:57 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
This is just too little code, theres no way of knowing what is going on...
I get an incorrect answer ?? what did you expect to get, what do you get...
dist_const=1.0; is the dist_const variable declared as const double or what ?? the name suggests it, and you can't change the value of any const type.
If you take a look at Valmonts solution to that
Code:
  //Determine the shipping rate based on distance.
  unsigned dist_rate = static_cast<unsigned>(distance/DIST_STEP);
You will by your logic see, that it is off by one, given a distance below 500 it results in 0, given a distance between 500 and 1000 gives a value of 1, so if you were to add one to this divission, you'd see the only time it dosn't add up, is when the distance is at an even 100.
You'd might look a bit further up into Valmonts code, and find the way he deals with the wt_rate could be a similar way you could deal with your distance...
Perhaps something like:
Code:
unsigned short int addition = distance%500 ? 1 : 0;
unsigned dist_rate = static_cast<unsigned>((distance/DIST_STEP) +addition);
Or perhaps by turning to the use of the standard C mathmatical ceil() function.
Code:
unsigned dist_rate = static_cast<unsigned>ceil(distance/DIST_STEP);
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote