How to use count to show how many inputted scores?

Hello! I wrote a program that when a user inputs all their test scores, it outputs the sum, the highest score, the lowest score, and how many scores were inputted. However, I do not know how to output how many scores were inputted. I was told that I'd need to use count to accomplish this, but I have no idea how, where, or when to use it. Any help would be greatly appreciated, thanks!!!

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
#include <iostream>
using namespace std;

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

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

    // Loop if input is between 0 and 100
    while(score > 0)
    {
        cin >> score;

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

        sum = sum + score;
        score++;
    }
    
        // Output showing how many scores (TO BE DETERMINED)

        // Output showing sum.
        cout << "\nYour 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
Try this:

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
#include <iostream>
using namespace std;

int main()
{
    double score, hi, lo;
    double sum = 0;
    int scores = 0;
    cout << "Please enter your test scores and write a negative number when you're finished:\n";

    // Loop if input is between 0 and 100
    while(score > 0)
    {
        cin >> score;
        scores++;
            // Finding lowest score
            if(score < lo)
                lo = score;
            // Finding highest score
            else if (score > hi)
                hi = score;

        sum = sum + score;
        score++;
    }
    
        // Output showing how many scores (TO BE DETERMINED)

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

        // Output showing total scores that were input.
        cout << "\nYour total is " << scores << ".\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;
}



Good luck!
That works!! Thank you!!

However, I've encountered a new problem: since the directions to my assignment make me end the loop with a negative number, my program sets that negative number as the lowest value. How do I make the SECOND lowest value = lo?
Hit enter at the end of line 14 and write:
1
2
if(score < 0)
break;

Also add the line 6:
double score, hi, lo = 1000;
But be careful--if the user enters all the numbers higher than 1000 the lowest score will be reported as 1000 which is incorrect.
I would try to think of a way around this.
Last edited on
Topic archived. No new replies allowed.