Problem solving homework assignment

Hi, I have a homework assignment similar to a problem that is on this website.

http://www.cplusplus.com/forum/beginner/143462/

Unfortunately, even after I make the corrections the post says to, it won't compile properly on visual studio. Could someone tell me what I'm doing wrong or point me in the right direction?

This is the problem and code I have so far which is similar to the code in the link I posted before. I just can't seem to get calcAverage to work correctly. It says:

Error C2660 'calcAverage': function does not take 6 arguments

and

too few arguments in function call

#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
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;
}


Thank you.

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


When you call the function calcAverage, it is missing one argument. You are trying to call the function with 5 arguments when your function prototype void calcAverage(int, int, int, int, int, int, double&); is 6 arguments (double&).

Thank you for the reply.

I added in score6 to the calcAverage function but now it says the function does not take 7 arguments.

Also, I modified lowest from int to double. I modified lowest to double because visual studio said a reference type "double&" cannot be initialized with a value of type "int"

#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;
double 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
calcAverage(score1, score2, score3, score4, score5, score6, 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 section is just confusing the life out of me. Did I misunderstand what you were telling me to do?
Last edited on
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;
double 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
calcAverage(score1, score2, score3, score4, score5, score6, 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;
}


I just compiled this and found no compiler errors. I'm using Visual Studio 2013
I'm using visual studio 2015 and it was giving me an error about average not being initialized in main. I deleted it and it started working.

Thank you so much for the help.
Ran into one more problem.

In line 71, the average is not calculated correctly, it should be score 1 through 6 being added minus the lowest score. If i add in int score 6 though, it fails to run again. Any suggestions?
When I did this homework a couple of years ago, I did this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void calcAverage(double avg1, double avg2, double avg3, double avg4, double avg5, double avg6)
{
	// Determine the variables
	double sum;
	double lowest;
	double avg;

	lowest = findLowest(avg1, avg2, avg3, avg4, avg5, avg6); // Call the function findLowest to determine the variable.

	sum = (avg1 + avg2 + avg3 + avg4 + avg5 + avg6) - lowest; // Substract the lowest number from the six scores.
	avg = sum / 5; // Determine the average

	cout << "The average for the five highest scores is " << avg << endl; // Display the message to notify the user.
	cout << "\n";

}


I hope this gives you an idea. This is not THE way, just a way.
Deleted Post
Last edited on
That's really helpful.

I'm trying to get the example you gave me of how you did it to work with my code but I'm having trouble getting it to work. I understand why it should work, but I'm not seeing why it won't work with mine. This is the first time I've had trouble like this with any of the work we've had. I just can't seem to figure out why something keeps going wrong.
My function prototypes are:
1
2
3
void getScore(int &);
void calcAverage(double, double, double, double, double, double); // Only the scores.
int findLowest(int, int, int, int, int, int);


The only 2 functions I would call on main is getScore and calcAverage:

1
2
3
4
5
6
7
8
9
10
	// The getScore() must be called by main once for each of the six scores.
	getScore(score1);
	getScore(score2);
	getScore(score3);
	getScore(score4);
	getScore(score5);
	getScore(score6);

	// The calcAverage() must be called just once by main, and must pass the six scores.
	calcAverage(score1, score2, score3, score4, score5, score6);


I would call the findLowest function on calcAverage function (Like I posted above in a couple of posts).

I hope this helps.
The last post got me to understand what I was looking at. Thank you very much for all your help. I just tested the program and it works. Now I can do my homework.

Thank you!!!
Topic archived. No new replies allowed.