Hi, this code is basically meant to work out an olympic dive score, Then print out a bar chart, using rectangles. But, the difficulty can be between 1.2 and 3.5. So an Int wont work, but when i change it, there is problems with the rect object, loss of precision or something. And that it needs an int, but of course the bar uses score, which can be anyhing, so that can't be a Int either. I'm really stuck on how to do this, any help would be great thanks.
Heres the code
BTW you may seen things to do with rainfall, i just copied it from an old program, but theyr are just prompts and comments. [ December 11, 2005: Message edited by: Graham Robinson ]
You might try using a scale like 1000 points is the distance between the bottom of the bar chart and the top of the bar chart. Use a double and round it to 2 places, then multiply is by 100 and that will give you a point in the chart.
Joined: Nov 23, 2005
Thanks, but i managed to do it using an int typecast, doesn't give as accurate results, but works.
For more accurate results, you might want to try Keith's suggestion. You said that the score can be anything between 1.2 and 3.5. Are you sure about this? The value of PI lies in this range. Is this a possible score value? Somehow I doubt it. In fact, there are probably MANY values between 1.2 and 3.5 that are not likely to be used as a score. However, it might be more helpful to describe what values CAN be used. For example, you can restrict the user input to only a few decimal places (2 for example). In this case, you can use an int that is really 100 times the actual score. This might take some extra processing for getting the input, but it will make drawing the bar chart much easier and more precise.
Alternatively, you can keep the float values that you have and just multiply them by 100 (or 1000 or whatever) before you graph them. The bar chart shows a relative value anyways, so such a scaling won't make any visible difference in the final result. You will still need to cast the result to an int after the multiplication, but it seems you have figured out how to do that.