yeah i have just noticed that its doing 6 times, because its counting 0,
also another thing that i have noticed is that when
int counter = 0;
while(counter <= 19)
it counts 20 students which is fine...
but after i put input (10 10 20 20 30 30 40 40 50 50 60 60 70 70 80 80 90 90 100 100)
this is the histogram i'm getting
0-29 *** <- 1 * is missing here... becasue 10 10 20 20 fall into one group but it prints only 3 * instead of 4 ?
Briefly, you need to examine the code you've written and figure out what it's doing and where it's deviating from what you want it to do. It's a matter of understanding the code you've written. Often that means examining each line and thinking about how that changes the state of the data. Another useful trick is to start at the end and work back. You have the output. What values are used to produce that output? How did they get there - what was the last instruction that set those values? That instruction took some data - what data did it use, and how did it get that way?
Look at the topic from a few days ago on "getting unstuck" and see if anything there helps.
Anyway, this is a new question - mark this topic as solved, try to find this bug for yourself, and post a new topic if you find you're really stuck.
ok i'll have a look at the other topic later on, i will mark this topic as solved soon, i have few little things to do, so i'll just wait till i get them done, just in case so when i get stock i wont have to make new topic :), and i'll just post here... if everything will be fine with the rest i will mark this topic as solved :). and ofc. award points for all useful answers :)
and as i though i have found a problem again ...
i managed to display the number of people failing, and number of people passing... as also the average mark... but i can not get it to display the lowest and the biggest mark achieved this is the code i came up with
Since you are not storing the data entered by the user, you cannot do this after the fact in a loop. You have to do it as you are reading in the data. Initialize highest to something low, like -1, and lowest to something high, like 101. Then when you read in a mark, if it is higher than highest, set highest to that mark. Similarly, if it is lower than lowest, set lowest to that mark.
so when first iteration is set to 0 the last input number i enter is compared to the 0, so the biggest take the last value entered ?
since i dont have all the values stored already i can not do comparing in a loop ?.
well if the value of biggest is less than marks so the condition is true, and then it goes to the next statement, and saves the biggest to b. but since i did not tell it what is the new biggest it wont save it ? the code know that the condition was met, but it doesnt know what is the new biggest. or it will ?
The next time through, the value of b is 1 (remember, we're in a for loop) and biggest is still 0. I don't know what marks is worth, but I'm assuming it's over 0, so biggest is assigned the value of b, which is 1.
And likewise the next time through, b is 2 (goes up by one each time) and biggest is 1 (that's what it was assigned to on the previous round), and so if biggest is still less than marks, biggest is once again assigned the value of b, which is 2.
And this will go on. Where will it stop, and what will be the value of b when it does stop?
ok i have fixed my problem :). the logic was fine, just what i have done is a have put this code outside my loop, and that was the reason why i was always getting biggest/lowest as the same number which was entered last!. now i can close the thread :)
this is what i came up with