HELP: Exclude the highest and lowest number...

This is a discussion on HELP: Exclude the highest and lowest number... within the C Programming forums, part of the General Programming Boards category; This was an optional assignment but I still wanted to do it... But I am having difficulty doing it. The ...

  1. #1
    C invoked dementia Ocin101's Avatar
    Join Date
    Jul 2009
    Posts
    14

    Question 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...
    Please help me which input method is better...
    And please help me on how to exclude the highest and lowest value of grade from the computation of the average score...

    THANKS!!!
    Last edited by Ocin101; 07-20-2009 at 06:30 AM.

  2. #2
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    And please help me on how to exclude the highest and lowest value of grade from the computation of the average score...
    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

    int main()
    {

    return 0;
    }

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Spidey View Post
    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().
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    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.

  5. #5
    C invoked dementia Ocin101's Avatar
    Join Date
    Jul 2009
    Posts
    14
    Thanks for reply!!!

    SPIDEY... sorry for the return value thing...
    But I am just using the getche(); thing for easy review from my compiler...
    But yes I do follow your advice for return 0;

    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!!!

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,462
    Quote Originally Posted by Ocin101
    What is your recommended input method?
    Use an array and convert your first version into a loop.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    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.

  8. #8
    C invoked dementia Ocin101's Avatar
    Join Date
    Jul 2009
    Posts
    14
    Thanks for the reply!

    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!

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,462
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    C invoked dementia Ocin101's Avatar
    Join Date
    Jul 2009
    Posts
    14
    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!!!

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,453
    Try posting questions and comments without YELLING all over the place.
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    C invoked dementia Ocin101's Avatar
    Join Date
    Jul 2009
    Posts
    14

    Smile

    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!!!


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting lowest and highest score from array
    By sjalesho in forum C Programming
    Replies: 6
    Last Post: 03-01-2011, 05:24 PM
  2. Replies: 3
    Last Post: 02-22-2009, 01:54 PM
  3. Trying to sort numbers from lowest to highest
    By jw232 in forum C++ Programming
    Replies: 21
    Last Post: 01-21-2008, 03:03 PM
  4. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM
  5. Can't find the lowest number in array?
    By Nate2430 in forum C++ Programming
    Replies: 1
    Last Post: 11-20-2001, 09:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21