Hi everyone I'm having a problem with this program giving me the wrong output. The question is

• void getScore() should ask the user for a test score, store it in a reference parameter variable. This function should be called by the main once for of the six scores to be entered by the user.

• double calcAverage() should calculate and return the average of the five highest scores. This function should be called just once by the main, and should be passed the six scores.

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

However the program always gives me the s6 as the lowest. this is what I have so far

double calcAverage(int s1, int s2, int s3, int s4, int s5, int &s6)
{
    int sum,lowScore;              
    double avg = 0;


   findLowest(s1, s2, s3, s4, s5, s6);
   avg = ((s1 + s2 + s3 + s4 + s5 + s6)-lowScore)/5;

}



return lowest;int findLowest(int s1, int s2, int s3, int s4, int s5, int s6)

{
    int lowest = s1; 

    if ( lowest < s2)
    {
    lowest = s2;
    }
    if ( lowest < s3)
    {
    lowest = s3;
    }
    if ( lowest < s4)
    {
    lowest = s4;
    }
    if ( lowest < s5)
    {
    lowest = s5; 
    }
    if ( lowest < s6)
    {
    lowest = s6;
    }



    return lowest;

your logic is wrong in the findLowest function
for example

if ( lowest < s2)
{
    lowest = s2;
}

means if lowest is less than the value of s2 you change the value of lowest to s2 even though s2 has a higher value than variable lowest
...try greater than and change the rest of the conditions

Hi I tried replacing it with > and it still just gave me the last input (s6). Here is the issue but I cant figure it out

int main()
{
   int test1, test2, test3, test4, test5, test6;  // 6 user inputs
   double average;

   cout << fixed
        << showpoint
        << setprecision(2);

   // Call getScore once for each test score to be input
   getScore(test1);
   getScore(test2);
   getScore(test3);
   getScore(test4);
   getScore(test5);
   getScore(test6);

   // Call calcAverage to calculate and display the average
   average = calcAverage(test1, test2, test3, test4, test5, test6);

   // Print the average
   printAverage(average, test6);

   system("PAUSE");
   return 0;

how can I get it to print lowestscore?

Edited 4 Years Ago by Lostelf

in printAverage( average, test6)

Test 6 is set as lowest scored since calcaverage is calling getlowest. so how can I get calcaverage to set test6 as lowest and print it?

It would be alot easier to see all the errors if you posted all of the code in one go
anyway, at the function calcAverage you didn't give variable lowScore any value and you didn't save the value returned by findLowest function to any variable
and lastly calcaverage didn't return any value

I don't know if this is what you're after but would it not be easier to make a vector and sort it and pop the last element off?

So:

Sorry if this was not what you're after.

Hey, I just threw together a quick bit of code showing what I discussed before if you're interested:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    /*
    Variables
    */
    vector<int> scores;
    int score;
    int averageScores;


    //Add Entered Numbers To Vector
    for(int i = 0; i < 6; i++) {
        cin >> score;
        scores.push_back(score);
    }

    //Print ELements
    for (int i = 0; i < scores.size(); i++) {
        cout << "Element: " << i << "  Score: " << scores[i] << endl;
    }


    //Sort Lowest TO Highest
    sort (scores.begin(), scores.end());


    //Print lowest number
    cout << "Lowest Number: " << scores[0] << endl;

    cout << endl;

    //Remove Lowest Number
    scores.erase(scores.begin());


    //Shows New Vector
    cout << "New Vector: " << endl;
     for (int i = 0; i < scores.size(); i++) {
        cout << "Element: " << i << "  Score: " << scores[i] << endl;
    }

    //Averages Scores Based Off of size of Vector
    for(int i = 0; i < scores.size(); i++) {
        averageScores += scores[i];
    }
    //Print Out Total + Average of Total
    cout << "Average Score Total: " << averageScores << endl;
    cout << "Average = " << averageScores/scores.size() << endl;

}

Hello lostelf and speakon. Thanks for posting your code. By posting your code, you have granted DaniWeb an exclusive copyright license to your code according to DaniWeb's terms of service. You may no longer use it and have no rights to you code. Please delete your code from your computer. As the Terms of Service say:

Any and all information posted on DaniWeb may not be copied or used elsewhere, in any way, shape, or form, either on the Internet or in print, without prior written permission from Dani Horowitz.

Further transmission of your source code material, such as in a personal project or in handing in an assignment, may be prosecutable as criminal copyright infringement.

Edited 4 Years Ago by Rashakil Fol

Comments
peanut
You'd think that at some point in time, you would grow up
more childish knee jerk over-reaction, sigh
that's all wrong
Fudding

With my moderator hat on, I say:

Ignore Rash's post, he doesn't have the slightest clue what he's talking about, almost everything he said is wrong and misguided. Of course, you are free to use your code for personal projects or assignment submissions. And you still own copyrights to your code.

Sorry for the inconvenience (or scare), Rash is just throwing a tantrum against the terms of services. Why he would inflict this on innocent posters is beyond my comprehension.

Comments
Well said

Hello lostelf and speakon. Thanks for posting your code. By posting your code, you have granted DaniWeb an exclusive copyright license to your code according to DaniWeb's terms of service. You may no longer use it and have no rights to you code. Please delete your code from your computer. As the Terms of Service say:

please dont harm me , this is my first post and didnt mean any problems. thank you

Comments
ignore Rashakil, he doesn't speak for Daniweb in any way

otherwise u can sort the scores like bubble sort and take the first value so that will be the lowest score or check lowest of scores

This article has been dead for over six months. Start a new discussion instead.