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);