Campbell Ritchie wrote:
How did you manage that? The correct average is 60¼. If you use integer arithmetic, that will come to 60Abdallah Taha wrote:. . . By using my code, if I use the file containing your data I got a average 51.
Piet Souris wrote:But I would expect a file with content like:
How else can I calculate an average?
Knute Snortum wrote:Well, you're not reading the entire file into an array, just one line at a time.
Are any of the fields in the data quoted? Like..
10, "Snortum, Knute", 13.32
In the line above, there are only three fields and the second field is "Snortum, Knute". If you have data like that, I'd suggests using Apache's Commons-CSV.
Piet Souris wrote:Oke. Then drop the line with continue and do this:
The idea is that if the guess element == -1, then we have processed it before (it had an exact match and so we must not gonna count it again)
Do you know about the break statement?
The rason for that is, say:
if guess[] = [3, 1, 2] and solution[] = [1, 5, 1] and if we check the 1 from guess[], then we find immediately a matching 1 at location 0. Now, if we do not break the loop here, we would also find a match at location 2, so that we find 2 matches instead of just 1.