Hi everyone,

First I want to say hello to everybody in this site and I hope that you'll welcome me as one of your nice members :o .
I've just started learning C++ language, and now I have to make a small program that counts the average grade for a number of homeworks for a number of students. This program should count only the big grades and leaves the last small grade, like if the user entered (56, 67, 98, 45, 67, 46, 89) the program would add them all together except the last small one which is 45, and then devide them by their number 6 and not 7. I have to put this inside a loop and also I need to use an if statement. I know how to do everything, but I just need to know how to make the part when the program should look for the smallest grade and ignore it. Please help guys and thanks inadvance :D

Member Avatar for iamthwee

I would use an array to store the numbers.

Hint: Loop through the array and use the comparison operator to find the smallest number.

yah.... using array is good idea for beginners..... n don't forget to subtract 1 from the total element number before finding the avg.... :P .... as i used to do such mistakes a lot!

*** after finishing ur coding, ask if u r still in any trouble!

thanks for replying. The arrys seem good but I havent studied it yet, Im supposed to learn it in two weeks. So, is there any other way? and is there anyway to show how to do it because as I said I,ve just started

Thanks again

All you need is a record of the total, and a record of the smallest.
When you're done, subtract the smallest from the total, and calculate the average.
No arrays necessary.

ya that's ok with me, but how do I get a record with the smallest? That's the question that I'm trying to find an answer for.

ya that's ok with me, but how do I get a record with the smallest? That's the question that I'm trying to find an answer for.

Get first entry and put it in a variable 'smallest'
qty = 0; // why zero here and not at the beginning? food for thought.
Now loop though each entry comparing new entry to smallest.
Remember to keep track of the qty of entries.
if newentry is less {
...
} else {
...
}
average = total/qty;

That should be enough to get you started. :)

ya that's ok with me, but how do I get a record with the smallest? That's the question that I'm trying to find an answer for.

How would you do it in real terms? Imagine someone calling out bingo numbers, and you're looking out for the smallest.
The first time he calls out a number, you remember that number, because it's the smallest number he's called so far.
Second time, you ask yourself "is this smaller than the smallest number?"
if the answer is yes, you remember that one
if not, you wait for the 3rd number... etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.