Please help with simple accumulators.....

Hello:
New here, so thanks for any advise on this....

I have a program due by midnite, and having issues with these simple accumulators.

Program is to read in a data file containing grades, accumulate grades into buckets, and print out results.

I'm reading the file fine and creating and array called "grades".

I then loop through the array, and try to increment counters if the grade falls into that bucket. The accumulators are not working, and I don't know why. After execution, all accumulators = 0.

Please advise.....
Thanks, Richard


here is the part of the code that has this loop....


for(int j = 0; j<(num-1); j++)
{
cout << "Entering loop..." << endl;
cout << grades[j] << endl;
if((grades[j] >= 0) && (grades[j] < 24))
range1 += 1;

else if((grades[j] >= 25) && (grades[i] <= 49))
range2 += 1;

else if((grades[j] >= 50) && (grades[i] <= 74))
range3 += 1;

else if((grades[j] >= 75) && (grades[i] <= 99))
range4 += 1;

else if((grades[j] >= 100) && (grades[i] <= 124))
range5 += 1;

else if((grades[j] >= 125) && (grades[i] <= 149))
range6 += 1;

else if((grades[j] >= 150) && (grades[i] <= 174))
range7 += 1;

else if((grades[j] >= 175) && (grades[i] <= 200))
range8 += 1;
}
Last edited on
It looks to me like you said grades[i] by mistake in a lot of the spots. Did you mean grades[j] instead?
Also in the future could you highlight your code with tags please?
http://www.cplusplus.com/articles/z13hAqkS/
Boy......Sometimes we are really dense, aren't we? Yes, you are right. I'm gona fix that, and rerun the program......rh
That fixed it....Thanks again. rh
Topic archived. No new replies allowed.