Lowest Score Drop

This is a discussion on Lowest Score Drop within the C++ Programming forums, part of the General Programming Boards category; Well, first of all, I would just like to say that I have half of the program right (at least ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    10

    Question Lowest Score Drop

    Well, first of all, I would just like to say that I have half of the program right (at least I think that i have it right).

    My program is supposed to do three things:
    1. void getscore()-should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered.
    2. voidcalcAverage()-should calculate and display the average of the four highest scores. This function should be called just once by main, and should be passed the five scores
    3. int findLowest()-shoudl find and return the lowest of the five scores pased to it. It should also be called by calcAverage, who uses the function to determine which of the five scores to drop



    Code:
    #include <iostream>
    #include <conio>
    using namespace std;
    
    //Function prototype
    void getscore(int&, int&, int&, int&, int&);
    void findLowest (int, int, int, int, int, int);
    void calcAverage (double)
    int main()
    {
            int LO, score1, score2, score3, score4, score5;
    
            getscore (score1, score2, score3, score4, score5);
            findLowest(LO, score1, score2, score3, score4, score5);
    
            getch();
            return 0;
    }
    
    
    
    void getscore (int &score1, int &score2, int &score3, int &score4, int &score5)
    {
            cout << "Enter first score: ";
            cin  >> score1;
            cout << "Enter second score: ";
            cin  >> score2;
            cout << "Enter third score: ";
            cin  >> score3;
            cout << "Enter fourth score: ";
            cin  >> score4;
            cout << "Enter fifth score: ";
            cin  >> score5;
    }
    
    int findLowest(int LO, int score1, int score2, int score3, int score4, int score5)
    {
    
            if((score1<score2)&&(score1<score3)&&(score1<score4)&&(score1<score5))
            {
            LO=score1;
            cout << LO;
            }
    
            else if((score2<score1)&&(score2<score3)&&(score2<score4)&&(score2<score5))
            {
            LO=score2;
            cout <<LO;
            }
    
            else if((score3<score1)&&(score3<score2)&&(score3<score4)&&(score3<score5))
            {
            LO=score3;
            cout << LO;
            }
    
            else if((score4<score1)&&(score4<score2)&&(score4<score3)&&(score4<score5))
            {
            LO=score4;
            cout << LO;
            }
            else if((score5<score1)&&(score5<score2)&&(score5<score3)&&(score5<score4))
            {
            LO=score5;
            cout << LO;
            }
    }
    But, now I am having trouble with the void calcAverage() part. this function should calculate and display the average of the four highest scores. This function should be called once by main, and should be passed the five scores.
    Does anyone have any idea how to do that

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    Have you learnt how to use loops and arrays? Doing it this way is rather tedious.
    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

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    10
    No, not really. Someone suggested that i used a loop, but I don't really see how that is possible. I am trying to stick to what I know.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    Suppose I changed the requirements and told you that you now have to deal with 1000 scores. I think you will find that your current method becomes rather impossible, unless you write a program to generate the resulting program for you. But to write that second program, you probably have to use loops.

    You might want to take some time to learn about loops and arrays. When used appropriately, they can simplify things and make life easier for you.
    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

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    10
    how can I use a loop in a function?? Is that even possible? What type would I use? Do/while, for, while???

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    how can I use a loop in a function?? Is that even possible?
    Of course it is possible. The tutorial I linked to has a code snippet with a for loop in the main() function.

    What type would I use? Do/while, for, while?
    Probably a for loop since you will be looping over an array with known bounds.
    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
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	char c;
    	int i;
    
    	// a do loop will go into the loop _at least_ once
    	do
    	{
    		cout << "enter a character or 'q' to stop: ";
    		cin >> c;
    	} while (c != 'q');
    
    	// a while loop checks the condition before entering the loop, ie it is not guaranteed to enter even once
    	while (c != 'q')
    	{
    		cout << "this wont get executed since: c == 'q'";
    	}
    
    	// for loop will loop until the middle statement (i < 3) is false, in this case 3 times
    	for (i = 0; i < 3; i++)
    	{
    		cout << "iteration #" << i << endl;
    	}
    }

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    10
    ??? I'm confused

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    I think nadroj was just demonstrating the possible loops without particular reference to your question.
    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
    Registered User
    Join Date
    Apr 2007
    Posts
    10
    oh okay sorry
    Thanks again

  11. #11
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    yes, as laserlight stated, i was just giving very basic examples of the three loops, without your homework.. so you can learn it.

    copy the code and run it.. and try and change things around.

  12. #12
    Registered User
    Join Date
    Apr 2004
    Posts
    173
    Code:
    Snipped ;)
    Note you still need to modify this. Notably in the calcAverage() function - you wanted the top 4 however in this case it gets the average of all the inputted scores. Also, if you want a constraint of having 5 scores then you will need to change the code to enforce it. These should be pretty simple modifications - if you still can't do them - start reading up on loops and vectors.
    Last edited by 0rion; 04-23-2007 at 04:32 AM. Reason: Snipped the code out
    The cost of software maintenance increases with the square of the programmer's creativity.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    Code:
    snipped with 0rion's code, for now
    Last edited by laserlight; 04-23-2007 at 04:43 AM.
    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

  14. #14
    Registered User
    Join Date
    Apr 2004
    Posts
    173
    Of course you can use STL functions to simplify them - but then he won't learn how loops are used
    The cost of software maintenance increases with the square of the programmer's creativity.

  15. #15
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    My point is that naya22 has not yet come back with code using what was recommended and demonstrated earlier in this thread: let's be patient and wait before giving out more code, especially that which is so close to the answer.
    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

Page 1 of 2 12 LastLast
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. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 12:33 PM
  3. trouble with creating a loop to read certain number of inputs
    By import tuner650 in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2008, 07:28 PM
  4. Lowest Score Drop - C++
    By getName(C-Dub) in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2008, 06:02 PM
  5. Drop Lowest Grade then Average
    By cmut in forum C Programming
    Replies: 4
    Last Post: 09-27-2002, 10:19 PM

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