How to make first lowest value not interfere with average calculation?

Hello! I wrote a program that when a user inputs all their test scores, it outputs some information including the average of their scores after dropping the highest and lowest scores. The directions in this assignment say to make it so that the loop breaks after a negative score is entered. This negative score, however, becomes the lowest score. How do I make it so that only the second lowest value is used to calculate the average instead? I tried adding ...

1
2
3
4
if(score < 0)
{
     break;
}


... but it didn't do anything. Please help! :(

Here is what I have thus far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
using namespace std;

int main()
{
    double score, hi, lo, avg;
    double sum = 0;
    double numScores = 0;

    cout << "Please enter your test scores and write a negative number when you're finished:\n";

    // Loop if input is a positive number
    while(numScores >= 0)
    {
        cin >> score;

            // Finding lowest score
            if(score < lo)
                lo = score;
            // Finding highest score
            else if (score > hi)
                hi = score;

        // Finding sum
        sum = sum + score;

        score++;
        numScores++;

        if(score < 0)
        {
            break;
        }
    }

    // Error if user inputs less than 3 scores
    if(numScores < 3)
    {
        cout << "\nERROR: Please enter more than 3 scores.\n";
    }

    // Output when user inputs more than 3 scores
    else
    {
        // Finding average
        avg = (sum - hi - lo)/(numScores - 2);

        // Output showing how many scores
        cout << "\nYou entered " << (numScores - 1) << " scores.\n";

        // Output showing average
        cout << "Your average is " << avg << ".\n";

        // Output showing sum.
        cout << "Your sum is " << sum << ".\n";

        // Output showing highest score
        cout << "Your highest score was " << hi << ".\n";

        // Output showing lowest score
        cout << "Your lowest score was " << lo << ".\n";
    }

    return 0;
}
Last edited on
Please don't open multiple threads on the same topic.
I apologize! I thought that since my last post had a title specific to an issue that was resolved, I should've opened a new one for another specific problem that wasn't in the title. I'll just keep it all on one thread next time. Thanks for letting me know!
No, that's ok!
Normally you would have gotten a much harsher ultimatum from some of the other members :)
Uh-oh! Thanks again :)
No problem! :)
Topic archived. No new replies allowed.