qwe

qwe
Last edited on
Where ever you have a cin >> variable, you should check cin's flags.
Your code is reading the students' marks just fine. Since you aren't printing any output, it might not be clear.

It looks like you intend to set the MrkXxxYyyBnd variable to indicate which band the of the historgram the mark should go into. Then I suppose you'll increment a variable corresponding to that band. The code would be shorter and if you used arrays instead:

- create an array of 4 integers initialized to zero. Call it histo This will be your histogram.

- create a second array of 4 integers and populate it with the highest value that can go into the corresponding histogram band. So the first one is 29, the second is 49 etc. Call it top

Now given a mark, you can update the histogram like this:
1
2
3
4
5
6
for (int i = 0; i < 4; ++i) {
    if (mark < top[i]) {  // does mark go in the i'th band?
        histo[i]++;          // increment the histogram
        break;               // exit the loop
    }
}

Topic archived. No new replies allowed.