Homework assignment I'm stuck on

I can't seem to get the void calcAverage part to work. can anyone help me.
this is what my instructor wants in C++.

Drop the Lowest Grade- write a program that calculates the average of a group of tests scores, where the lowest score in the group is dropped. It must have the following functions:
void getScore() should ask the user for a test score, store it in a reference paramenter variable, and validate it. This function must be called by main once for each of the 6 scores to be entered.
validate the test scores.

void calcAverage() should calculate the average and display the 5 highest scores. This function must be called once by main.

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

Here's what I have so far

//This program gets six test scores and drops the lowest and calculates the average

#include <iostream>
#include <iomanip>
using namespace std;

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


int main()
{
int score1, score2, score3, score4, score5, score6;
int lowest;
double average;

//Get the users test scores
getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);
getScore(score6);

//Output control
cout << fixed << showpoint << setprecision(2);

//Get the lowest test score
lowest = findLowest(score1, score2, score3, score4, score5, score6);
cout << "The lowest test score is: " << lowest << endl;

//Calculate the average test score
average = calcAverage(score1, score2, score3, score4, score5, &lowest);

return 0;
}

void getScore(int &score)
{
cout << "Please enter your test score (enter a value from 1 to 100): ";
cin >> score;
while (score < 1 || score > 100)
{
cout << "Error: Please enter a test score from 0 to 100!";
cin >> score;
}
}
int findLowest(int score1, int score2, int score3, int score4, int score5, int score6)
{
int lowest;
lowest = score1;
if (score2 < lowest)
lowest = score2;
else if (score3 < lowest)
lowest = score3;
else if (score4 < lowest)
lowest = score4;
else if (score5 < lowest)
lowest = score5;
else if (score6 < lowest)
lowest = score6;
return lowest;
}
void calcAverage(int score1, int score2, int score3, int score4, int score5, int lowest, double& average)
{
average = (score1 + score2 + score3 + score4 + score5 - lowest) / 5;
}
This is just for me so I can look at your code.
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
#include <iostream>
#include <iomanip>

using namespace std;

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


int main()
{
    int score1, score2, score3, score4, score5, score6;
    int lowest;
    double average;

    //Get the users test scores
    getScore(score1);
    getScore(score2);
    getScore(score3);
    getScore(score4);
    getScore(score5);
    getScore(score6);

    //Output control
    cout << fixed << showpoint << setprecision(2);

    //Get the lowest test score
    lowest = findLowest(score1, score2, score3, score4, score5, score6);
    cout << "The lowest test score is: " << lowest << endl;

    //Calculate the average test score
    average = calcAverage(score1, score2, score3, score4, score5, &lowest);

    return 0;
}

void getScore(int &score)
{
    cout << "Please enter your test score (enter a value from 1 to 100): ";
    cin >> score;
   
    while (score < 1 || score > 100)
    {
        cout << "Error: Please enter a test score from 0 to 100!";
        cin >> score;
    }
}

int findLowest(int score1, int score2, int score3, int score4, int score5, int score6)
{
    int lowest;
    lowest = score1;
   
    if (score2 < lowest)
        lowest = score2;
    else if (score3 < lowest)
        lowest = score3;
    else if (score4 < lowest)
        lowest = score4;
    else if (score5 < lowest)
        lowest = score5;
    else if (score6 < lowest)
        lowest = score6;
    
return lowest;
}

void calcAverage(int score1, int score2, int score3, int score4, int score5, int lowest, double& average)
{
    average = (score1 + score2 + score3 + score4 + score5 - lowest) / 5; 
}
Now when you call the calcAverage function, you have it looking to receive six int-types and one double-reference-type.

In main, when you call the calcAverage function:
1
2
    //Calculate the average test score
    average = calcAverage(score1, score2, score3, score4, score5, &lowest);


You are sending the address of lowest - &lowest. Get rid of "&" because that passes the ADDRESS of lowest and not the VALUE.

Secondly, if you look at when you call the calcAverage function, you are assigning the value of calcAverage to average. Then you go into the actual function and assign it the first time.
So to fix this, simply call the function without average = with the adjustment I stated previously.
Topic archived. No new replies allowed.