question concerning averages and finding the max and min.

Hello!!
if anyone could help this would be great. I'm tring to figure out how to find the max and min number out of a set of user inputs numbers in a program. for example the user inputs 4 set of numbers like 30 79 91 and 4 and i want to add the sum of them but subtract the max and min numbers. How would I do this??
Programming is thinking. Tell me, what's the largest of the following 4 numbers?

30 79 91 4

How did you know that? Now program that.
I know how to do that it just that its hard for me to put it into code
this is what I came up with but it doesnt seem to work on my program. I'm doing loops

1
2
3
4
5
6
7
if ( score > biggestScoreSoFar )
				biggestScoreSoFar = score;
			else ( score < smallestScoreSoFar);
				smallestScoreSoFar = score;

			
			int adjustedAverageScore = (sum - smallestScoreSoFar - biggestScoreSoFar) / count;
Now that is a much better question. You have gone from essentially asking us to do your homework for you, to giving us some code you're having trouble with.

Firstly, this makes no sense
else ( score < smallestScoreSoFar)
I suspect you meant
else if ( score < smallestScoreSoFar)
but this has a problem. What happens if only one number is entered? Then that should be the biggest AND smallest, right? So each input number needs to be checked for being the biggest AND for being the smallest, like this:

1
2
3
4
5
6
7
8
9
if ( score > biggestScoreSoFar )
{ 
  biggestScoreSoFar = score;
}

if( score < smallestScoreSoFar)
{
  smallestScoreSoFar = score;
}


What values are you setting biggestScoreSoFar and smallestScoreSoFar to at the start?

You can still improve your questions, though.
what I came up with but it doesnt seem to work on my program
is not nearly enough. What does it do that you don't like, or not do? Does it compile? Does it link? Does it crash? Does it produce output? What output, for what input? Do you get the idea?
Last edited on
I set both to 0
1
2
int smallestScoreSoFar = 0;
int biggestScoreSoFar = 0;


When i comppile it, it will not sum up the scores and subtract the smallestScoreSoFar and the bigestScoreSoFar it gives me a random negative number.


sorry if I'm not explaining it correctly I am new to C++ programming and I get lost really easily. I'm trying to correct a previous assignment that was given to me.
int smallestScoreSoFar = 0;

So what happens if the scores are 3 and 4 and 7? What is the smallest score? 3. What will your code say is the smallest score? 0. See the problem?

Let's make it simpler. Let's say the user enters just one score. The number 5. What will your code say is the smallest score?
I'm understanding your example but then what is the value i need to set it up too? i thought 0 was right?
Topic archived. No new replies allowed.