void function already has a body

Hello all. First time poster here. I am working on a program for school and i have an error I haven't been able to solve. I am trying to get 5 test scores by calling a void function but not using the ampersand. I looked back in my book but cant figure out why I still get this error. I also searched on here but haven't had much luck. I looked for a missing bracket or semicolon. it says the error is on void getScores(double score2)

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

#include <iostream>
#include <iomanip>

using namespace std;

//function prototypes
void getScores(double);
void calcAverage(double, double, double, double, double);
double findLowest(double, double, double, double, double);

int main()
{
	double score1; //to hold first score
	double score2; //to hold second score
	double score3; //to hold third score
	double score4; //to hold fourth score
	double score5; //to hold fifth score

	//calling for the five test scores
	getScores(score1);
	getScores(score2);
	getScores(score3);
	getScores(score4);
	getScores(score5);

	//display average score after dropping the lowest and highest scores
	calcAverage(score1, score2, score3, score4, score5);

	return 0;
}

//get score function asks the user to enter a test score, stores it in a variable, and validates it
void getScores(double score1)
{
	//get test scores
	cout << " Enter a test score: ";
	cin >> score1;

	//validation
	while (score1 < 0.0 || score1 > 100.1)
	{
		cout << " The test score must be between 0.0 and 100\n"
			<< " Enter a valid test score: ";
		cin >> score1;
	}
}
 void getScores(double score2)
{
	//get test scores
	cout << " Enter a test score: ";
	cin >> score2;

	//validation
	while (score2 < 0.0 || score2 > 100.1)
	{
		cout << " The test score must be between 0.0 and 100\n"
			<< " Enter a valid test score: ";
		cin >> score2;
	}
}
void getScores(double score3)
{
	//get test scores
	cout << " Enter a test score: ";
	cin >> score3;

	//validation
	while (score3 < 0.0 || score3 > 100.1)
	{
		cout << " The test score must be between 0.0 and 100\n"
			<< " Enter a valid test score: ";
		cin >> score3;
	}
}
void getScores(double score4)
{
	//get test scores
	cout << " Enter a test score: ";
	cin >> score4;

	//validation
	while (score4 < 0.0 || score4 > 100.1)
	{
		cout << " The test score must be between 0.0 and 100\n"
			<< " Enter a valid test score: ";
		cin >> score4;
	}
}
void getScores(double score5)
{
//get test scores
cout << " Enter a test score: ";
cin >> score5;

//validation
while (score5 < 0.0 || score5 > 100.1)
{
	cout << " The test score must be between 0.0 and 100\n"
		<< " Enter a valid test score: ";
	cin >> score5;
}
}

//calcAverage function calculates and displays the average of the three scores that remain after dropping the highest
//and lowest scores the student received
void calcAverage(double score1, double score2, double score3, double score4, double score5)
{
	//getting lowest score
	double lowest = findLowest(score1, score2, score3, score4, score5);

	//calculating the average of all 5 test scores
	double total = score1 + score2 + score3 + score4 + score5;

	//drops the lowest test score and calculates the remaining average
	double average = (total - lowest) / 3.0;

	//display the average score with the lowest score dropped
	cout << "\nAfter dropping the lowest score of " << lowest << "the average test score was " << setprecision(1) << fixed << showpoint << average << ".\n";
}

// finds lowest function finds and returns the lowest of the five test scores
double findLowest(double score1, double score2, double score3, double score4, double score5)
{
	double lowest; //holds the lowest score
	//assuming the first score is the lowest
	lowest = score1;

	//checking to see if its true
	if (lowest > score2)
		lowest = score2;
	if (lowest > score3)
		lowest = score3;
	if (lowest > score4)
		lowest = score4;
	if (lowest > score5)
		lowest = score5;
	return lowest;
}
Last edited on
Your issue is that you're essentially creating the "getScores" function over and over with the same parameters. All of the functions have 1 parameter and all have the double type. The only difference is that you changed the variable name which doesn't count as a different function.
Last edited on
this is the actual error message
Error 1 error C2084: function 'void getScores(double)' already has a body
shecter wrote:
this is the actual error message
Error 1 error C2084: function 'void getScores(double)' already has a body


Yea, it doesn't think that it's a different function. To properly overload functions, I suggest reading the first section of the tutorial on this page: http://www.cplusplus.com/doc/tutorial/functions2/

Good luck with your project!
Last edited on
Excellent! Thank you for the link I greatly appreciate it.
Topic archived. No new replies allowed.