Skip to content
Advertisement

Program ignoring the last row in the file in calculation

I have a text file with data that looks like this (TestData.txt):

JavaScript

My code parses the file and does some calculations with it.

However, in the method arrangeList() within which calls another method called getTestAvg() (calculates column means), the program ignores Tyler Perez’s scores.

I noticed that the results I am getting were inaccurate so I went and printed the whole 2d array with all the test scores and the last column is nowhere to be found.

My entire code is below and I hope someone could point out what causes this.

I keep getting an IndexOutOfBounds error whenever I try to switch N (# of students) and M (# of tests) to see what happens. At first, I have 10 students and 10 tests, and all the calculations were correct, but when I added another student, the calculations became inaccurate.

I apologize in advance if my code isn’t as well-designed as I’m not an experienced programmer.

JavaScript

Here are the numbers I’m supposed to be getting (top) compared to what my program outputs (bottom). enter image description here enter image description here

Advertisement

Answer

As the other responses already stated, you had quite the issue with your variables and loops. I now changed N to # of students and M to # of tests to be as you stated in your question.

Next time, maybe try to improve your variable naming, so you don’t get confused. (e.g. switch out n and m for s (students) and t (tests), if you like your variable names short).

This should work now. Just check against your code to see the changes.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement