Finding the lowest score

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • namcintosh
    New Member
    • Apr 2007
    • 67

    #31
    Alright, then, here is my program.

    I've already ran the program, but I still want you to run int and see what you think of it.


    Code:
    #include <iostream>
    #include <conio>
    using namespace std;
    
    //Function prototype
    void getscore(int&, int&, int&, int&, int&);
    int findLowest (int, int, int, int, int, int);
    void calcAverage (int, int, int, int, int, int, int);
    int main()
    {
            int average, score1, score2, score3, score4, score5, small;
    
            getscore (score1, score2, score3, score4, score5);
            calcAverage (average, score1, score2, score3, score4, score5, small);
            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;
    }
    
    void calcAverage (int average, int score1, int score2, int score3, int score4, int score5, int small)
    {
             
    
            average = ((score1 + score2 + score3 + score4 + score5)-small)/4;
    
            cout << average;
    
    }
    int findLowest(int small, int score1, int score2, int score3, int score4, int score5)
    {
            small =score1;
    
            if(small>score2)
            {
            small=score2;
            }
            if(small>score3)
            {
            small=score3;
            }
            if(small>score4)
            {
            small=score4;
            }
            if(small>score5)
            {
            small=score5;
            }
            return small; 
    }
    Thanks for the encouragement, goys!!
    Last edited by namcintosh; Apr 24 '07, 03:56 PM. Reason: Correction

    Comment

    • Savage
      Recognized Expert Top Contributor
      • Feb 2007
      • 1759

      #32
      Can't see any error.

      It should work,probably :D

      Savage

      Comment

      • namcintosh
        New Member
        • Apr 2007
        • 67

        #33
        Originally posted by Savage
        Can't see any error.

        It should work,probably :D

        Savage
        Uh- oh, I think I ran into a problem:

        When I entered the values 100, 100, 100, 100, 100, it gave me an average of 125. Why did that happen???

        Comment

        • Savage
          Recognized Expert Top Contributor
          • Feb 2007
          • 1759

          #34
          Originally posted by namcintosh
          Uh- oh, I think I ran into a problem:

          When I entered the values 100, 100, 100, 100, 100, it gave me an average of 125. Why did that happen???
          In main set average to 0 before calling the function.

          Comment

          • namcintosh
            New Member
            • Apr 2007
            • 67

            #35
            Originally posted by Savage
            In main set average to 0 before calling the function.
            I tried that, and this is what happened:

            Code:
            int main()
            {
                    int average = 0, score1, score2, score3, score4, score5, small;
            
                    getscore (score1, score2, score3, score4, score5);
                    calcAverage (average, score1, score2, score3, score4, score5, small);
                    getch();
                    return 0;
            }
            Enter first score: 100
            Enter second score: 100
            Enter third score: 100
            Enter fourth score: 100
            Enter fifth score: 100
            125
            It's still outputting 125.

            Comment

            • Ganon11
              Recognized Expert Specialist
              • Oct 2006
              • 3651

              #36
              Hint: When, in your program, are you finding small?

              Comment

              • namcintosh
                New Member
                • Apr 2007
                • 67

                #37
                Originally posted by Ganon11
                Hint: When, in your program, are you finding small?
                I'm finding small in my findLowest() function

                Comment

                • Savage
                  Recognized Expert Top Contributor
                  • Feb 2007
                  • 1759

                  #38
                  Originally posted by namcintosh
                  Uh- oh, I think I ran into a problem:

                  When I entered the values 100, 100, 100, 100, 100, it gave me an average of 125. Why did that happen???
                  U are missing caller for findLowest() inside main() so it's just seting it to 0:

                  average=(100+10 0+100+100+100)-0)/4=125;

                  This should fix that!!

                  Savage

                  Comment

                  • namcintosh
                    New Member
                    • Apr 2007
                    • 67

                    #39
                    Originally posted by Savage
                    U are missing caller for findLowest() inside main() so it's just seting it to 0:

                    average=(100+10 0+100+100+100)-0)/4=125;

                    This should fix that!!

                    Savage
                    I tried that, and the same thing happened.

                    Actually, here are the instructions:
                    void calcAverage()-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.

                    int findLowest()-should find and return the lowest of the five scores passed to it. It should be called by the calcAverage, who uses the function to determine which of the five scores to drop.

                    So, what am I doing wrong??:-(

                    Comment

                    • Savage
                      Recognized Expert Top Contributor
                      • Feb 2007
                      • 1759

                      #40
                      Originally posted by namcintosh
                      I tried that, and the same thing happened.

                      Actually, here are the instructions:
                      void calcAverage()-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.

                      int findLowest()-should find and return the lowest of the five scores passed to it. It should be called by the calcAverage, who uses the function to determine which of the five scores to drop.

                      So, what am I doing wrong??:-(
                      How did u added the caller was it like:

                      small=findLowes t(score1,score2 ,score3,score4, score5);


                      ???

                      Savage

                      Comment

                      • namcintosh
                        New Member
                        • Apr 2007
                        • 67

                        #41
                        Originally posted by Savage
                        How did u added the caller was it like:

                        small=findLowes t(score1,score2 ,score3,score4, score5);


                        ???

                        Savage
                        What do u mean, how did I add the caller

                        Comment

                        • Savage
                          Recognized Expert Top Contributor
                          • Feb 2007
                          • 1759

                          #42
                          Originally posted by namcintosh
                          What do u mean, how did I add the caller

                          Sorry,I was asking u how have u called function inside main.Was it called the same way as in my previous post?


                          PS:I have need for sleep.(Zzzzzzzz zZzzzzzz)


                          Savage

                          Comment

                          • namcintosh
                            New Member
                            • Apr 2007
                            • 67

                            #43
                            Originally posted by Savage
                            Sorry,I was asking u how have u called function inside main.Was it called the same way as in my previous post?


                            Savage
                            Yes, it was, and I still ran crazy. Run my program, please and you will see what I mean.

                            Comment

                            • Savage
                              Recognized Expert Top Contributor
                              • Feb 2007
                              • 1759

                              #44
                              Originally posted by namcintosh
                              Yes, it was, and I still ran crazy. Run my program, please and you will see what I mean.
                              i fixed it:

                              This is what I have changed:


                              int findLowest (int, int, int, int, int);//there was six of them small is unecsasary.

                              //main
                              int average=0, score1=0, score2=0, score3=0, score4=0, score5, small=0;

                              //getscore
                              small=findLowes t(score1,score2 ,score3,score4, score5);
                              //calcAverage
                              //gethc and return

                              and finaly ur function:

                              int small =score1;//we don't pass small to the function therefore we create another variable.

                              I have runed this and output is 100.

                              Savage

                              Comment

                              • namcintosh
                                New Member
                                • Apr 2007
                                • 67

                                #45
                                Originally posted by Savage
                                i fixed it:

                                This is what I have changed:


                                int findLowest (int, int, int, int, int);//there was six of them small is unecsasary.

                                //main
                                int average=0, score1=0, score2=0, score3=0, score4=0, score5, small=0;

                                //getscore
                                small=findLowes t(score1,score2 ,score3,score4, score5);
                                //calcAverage
                                //gethc and return

                                and finaly ur function:

                                int small =score1;//we don't pass small to the function therefore we create another variable.

                                I have runed this and output is 100.

                                Savage
                                I hate to sound like a complete martian, but can you please explain to me what each line means???

                                Comment

                                Working...