# HELP: Exclude the highest and lowest number...

• 07-20-2009
Ocin101
HELP: Exclude the highest and lowest number...
This was an optional assignment but I still wanted to do it... But I am having difficulty doing it.

The assignment said that the user must input 6 quiz grades, and get the average of the quizzes excluding the highest and lowest grade, and do all this for 5 students.

Sample Output:

Enter Student Scores:
Q1=50
Q2=70
Q3=100
Q4=50
Q5=40
Q6=90
Average Score:65 (excluding the highest and the lowest scores)

Enter Student Scores:
Q1=60
Q2=70
Q3=100
Q4=50
Q5=40
Q6=90
Average Score:67.5 (excluding the highest and the lowest scores)

Enter Student Scores:
Q1=50
Q2=70
Q3=90
Q4=50
Q5=40
Q6=70
Average Score:60 (excluding the highest and the lowest scores)

Enter Student Scores:
Q1=80
Q2=70
Q3=100
Q4=50
Q5=40
Q6=90
Average Score:72.5 (excluding the highest and the lowest scores)

Enter Student Scores:
Q1=85
Q2=75
Q3=80
Q4=90
Q5=50
Q6=95
Average Score:82.5 (excluding the highest and the lowest scores)

I am having difficulty on how to exclude the highest and lowest grade input so I cannot proceed with computing the average.

I made two experimental code versions because I don't know which of the two "GRADE INPUT" methods I should use...

Input Method 1

Code:

```#include<stdio.h> float q1,q2,q3,q4,q5,q6,s; /*the set of variables are not final*/ main() { clrscr(); printf("Please input scores for 6 quizzes:"); printf("\nQuiz1: "); scanf("%f",&q1); printf("\nQuiz2: "); scanf("%f",&q2); printf("\nQuiz3: "); scanf("%f",&q3); printf("\nQuiz4: "); scanf("%f",&q4); printf("\nQuiz5: "); scanf("%f",&q5); printf("\nQuiz6: "); scanf("%f",&q6); for(s=1;s<=5;s++) /*to repeat the input and computation of grades for 5 times*/           {           /*then I don't know what to do next*/           /*I think it should have contained the code for excluding the min and max value and the average of the 4 values left*/           } return 0; }```
Input Method 2:

Code:

```#include<stdio.h> float s,g,q; /*the set of variables are not final*/ main() { clrscr(); for(s=1;s<=5;s++) /*to repeat the input, computation, and output for 5 students*/           {           printf("Please input scores for 6 quizzes:");           for(g1;g1<=6;g++) /*to input quiz scores for 6 times to correspond for the 6 quizzes required*/                     {                     printf("Quiz%f",g); scanf("%f",&q);                     /*then I don't know what to do next*/```
I don't know which is the better input method for the situation...

THANKS!!!:)
• 07-20-2009
Spidey
Quote:

Try to think about it first, excluding the smallest and largest numbers is relatively simple. Think about it first. Write some code and then ask for help if your stuck.

Again, I told you this 3 times already - Your main must return a Value

Quote:

int main()
{

return 0;
}
• 07-20-2009
BEN10
Quote:

Originally Posted by Spidey
Try to think about it first, excluding the smallest and largest numbers is relatively simple. Think about it first. Write some code and then ask for help if your stuck.

Again, I told you this 3 times already - Your main must return a Value
Code:

```int main() { return 0; }```

BTW it's optional to use return 0 in the main function, but it should have a proper return type like int main().
• 07-20-2009
Spidey
Quote:

BTW it's optional to use return 0 in the main function, but it should have a proper return type like int main().
Yes, that's what I meant.
return 0 was just an example.
• 07-20-2009
Ocin101

SPIDEY... sorry for the return value thing...
But I am just using the getche(); thing for easy review from my compiler...

BUT... I CAN'T MOVE ON TO THINKING ON HOW TO EXCLUDE THE MIN AND MAX VALUES BECAUSE I CAN'T DECIDE WHICH INPUT METHOD I SHOULD CHOOSE...

What is your recommended input method?
Then I could start thinking for the EXCLUSION PART...

THANKS!!!
• 07-20-2009
laserlight
Quote:

Originally Posted by Ocin101
What is your recommended input method?

Use an array and convert your first version into a loop.
• 07-20-2009
Spidey
Quote:

BUT... I CAN'T MOVE ON TO THINKING ON HOW TO EXCLUDE THE MIN AND MAX VALUES BECAUSE I CAN'T DECIDE WHICH INPUT METHOD I SHOULD CHOOSE...
Well, since you have 5 students and each of them have 5 quizzes. You could use a 2D array to represent the individual quizzes. This will make your entire program easier to write as well.
• 07-20-2009
Ocin101

I had read of this array thing... BUT WE WERE NOT STILL TAUGHT ABOUT ARRAYS SO I AM NOT FAMILIAR WITH IT...

Sorry for being ignorant from ARRAYS...

Is there a way to solve this problem without using arrays?
I would really like to avoid using arrays for now...

If not possible, HOW DO I USE ARRAYS?

Thanks for replying to my questions!
:)
• 07-20-2009
laserlight
Quote:

Originally Posted by Ocin101
Is there a way to solve this problem without using arrays?

Well... to be honest, for what you want to do, it is indeed true that an array is unnecessary. The second version that you have in mind is actually more efficient: keep track of the total, the maximum, and the minimum. When you are done with the input, subtract the maximum and minimum from the total, then compute the mean.
• 07-20-2009
Ocin101
LASERLIGHT...

I tried doing the SUMMATION PART AND TESTED WITH PRINTING THE SUM ITSELF...
IT WAS WORKING FINE... I GET THE EXACT SUM EVERY STUDENT..

MY WORKING CODE:

Code:

```#include<stdio.h> float s,g,q,a,sum; main() { clrscr(); for(s=1;s<=5;s++)         {         a=0;         printf("Please input scored for 6 quizzes:");         for(g=1;g<=6;g++)                 {                 printf("\nQuiz%.0f:",g);                 scanf("%f",&q);                 sum=a+q;                 a=sum;                 }         printf("\n\nSUM:%.2f\n\n",sum);         } getche(); }```
HOWEVER, IT IS REALLY MIND BOGGLING ON HOW TO IDENTIFY WHICH IS THE HIGHEST AND WHICH IS THE LOWEST VALUE...

CAN YOU PLEASE GIVE ME ANY CLUE?

THANKS A LOT!!! :)
• 07-20-2009
When you have a problem to solve with a program, see if it relates to something you can do, or have done, yourself - without the computer.

For instance, if I were to say "I'll show you 4 coins for you to look at, one at a time. When you've seen each coin, I'll want you to tell me which coin had the greatest value, and which had the least value."

How would you do that:

The first coin I show you becomes both the largest and the smallest, in value.

The second coin, might become the new largest or smallest, depending on it's value.

Specifically,

* if the second coin is less than the first coin, it becomes the new smallest coin.
* if the second coin is greater than the first coin, it becomes the new largest coin.

For every coin after the first one, you have to make these two comparisons.

So, a for or do while loop, could be used to make these two comparisons for each coin:

Code:

```//assign minimumCoin and maximumCoin to the first coin, up here for(i = 0; i < NumberOfCoins; i++)  {   if (newcoin < minimumCoin)       minimumCoin = newcoin;   if(newcoin > maximumCoin)       maximumCoin = newcoin; }```
Hope that helps.
• 07-20-2009
Salem
Try posting questions and comments without YELLING all over the place.
How To Ask Questions The Smart Way
• 07-21-2009
Ocin101
Well...

Sorry, the CAPS thing is actually MEANT JUST FOR EMPHASIS...

I don't mean to YELL...

Anyways... SORRY...

And I was able to solve my problem already...

THANKS A LOT TO THOSE WHO REPLIED AND GAVE ME CLUES!!!

:D