lowest score

When writing my code it continues to give me an error with my math. After calculating my scores I get a:
6.95322e-310The average of the four highest test scores is 3.47661e-310.

I used all 90% for my scores except my last score which was 0%
Here is the code i have so 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 #include <iostream>
using namespace std;

void intro();
void getScore(double&);
void calcAverage(double, double, double, double, double);
int findLowest(double, double, double, double, double);

int main()
{
    double score1,
    score2,
    score3,
    score4,
    score5;
    
    intro();
    getScore(score1);
    getScore(score2);
    getScore(score3);
    getScore(score4);
    getScore(score5);
    calcAverage(score1, score2, score3, score4, score5);
    
}

void intro()
{
    cout << "This program will take five test scores from the user and calculate\n";
    cout << "their average after dropping the lowest score.\n\n";
}

void getScore(double & score)
{
    static double tScore;
    tScore++;
    
    cout << "Please enter a test score. ";
    cin >> tScore;
    
    while (tScore < 0 || tScore > 100)
    {
        cout << "Valid test scores range from 0 - 100.\n";
        cout << "Please enter a test score. ";
        cin >> tScore;
    }
}

void calcAverage(double grd1, double grd2, double grd3, double grd4, double grd5)
{
    double lowest;
    double sum;
    double average;
    
    cout << grd1;
    
    lowest = findLowest(grd1, grd2, grd3, grd4, grd5);
    sum = (grd1 + grd2 + grd3 + grd4);
    average = (sum / 4);
    
    
    cout << "The average of the four highest test scores is "<<
    average << ".\n\n";
}

int findLowest(double tScore1, double tScore2, double tScore3, double tScore4, double tScore5)
{
    double lowest = tScore1;
    
    if (lowest > tScore2)
        lowest = tScore2;
    if (lowest > tScore3)
        lowest = tScore3;
    if (lowest > tScore4)
        lowest = tScore4;
    if (lowest > tScore5)
        lowest = tScore5;
    
    return 0;
}
Your getScore() function doesn't do anything: You are not returning the result! Get that fixed and your program will work better.
I believe it is your getScore function. It's using a local variable "tScore" to obtain input which doesn't affect "score" at all.

So I would suggest changing your getScore function to something along the lines of:

1
2
3
4
5
6
7
8
9
10
11
12
13
void getScore(double & score)
{
    
    cout << "Please enter a test score. ";
    cin >> score;
    
    while (score < 0 || score > 100)
    {
        cout << "Valid test scores range from 0 - 100.\n";
        cout << "Please enter a test score. ";
        cin >> score;
    }
}

Last edited on
awesome thanks for the help
No problem. The rest looks pretty good with maybe a little bit of touch ups (maybe accepting a 5th parameter for your calcAverage function to get the 5th grade).

Good luck in your ventures.
Topic archived. No new replies allowed.