Problems with Functions

I've been working on this problem: https://gyazo.com/c3ff55a0cd8115dbe7bec96c69e06108

The program looks like it works, but "score" always outputs "3.08532e+61".


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
void getJudgeData(double& jscore, int& numjudge);
double calcScore(double& score, double& j1, double& j2, double& j3, double& j4, double& j5, double& highest, double& lowest);

double getHighest(double& highest, double& j1, double& j2, double& j3, double& j4, double& j5);
double getLowest(double& lowest, double& j1, double& j2, double& j3, double& j4, double& j5);

int main()
{
	double jtotal, jscore, j1, j2, j3, j4, j5, score, highest, lowest;
	int numjudge;

	numjudge = 1;

	getJudgeData(jscore, numjudge);
	j1 = jscore;
	numjudge = numjudge + 1;

	getJudgeData(jscore, numjudge);
	j2 = jscore;
	numjudge = numjudge + 1;

	getJudgeData(jscore, numjudge);
	j3 = jscore;
	numjudge = numjudge + 1;

	getJudgeData(jscore, numjudge);
	j4 = jscore;
	numjudge = numjudge + 1;

	getJudgeData(jscore, numjudge);

	calcScore(score, j1, j2, j3, j4, j5, highest, lowest);

	cout << score << endl;

	return 0;
}

void getJudgeData(double& jscore, int& numjudge)
{
	cout << "Input the score given by Judge " << numjudge << ".\n(score between 1-10)" << endl;
	cin >> jscore;
}

double calcScore(double& score, double& j1, double& j2, double& j3, double& j4, double& j5, double& highest, double& lowest)
{
	double total;


	double findLowest(double, double, double, double, double);
	double findHighest(double, double, double, double, double);

	total = j1 + j2 + j3 + j4 + j5;
	score = total - highest - lowest;
	score = score / 3;

	return score;

}

double findLowest(double lowest, double j1, double j2, double j3, double j4, double j5)

{
	lowest = j1;
	if (j2 < j1)
	{
		lowest = j2;
	}
	if (j3 < j1)
	{
		lowest = j3;
	}
	if (j4 < j1)
	{
		lowest = j4;
	}
	if (j5 < j1)
	{
		lowest = j5;
	}
	return lowest;
}

double findHighest(double highest, double j1, double j2, double j3, double j4, double j5)
{
	highest = j1;
	if (j2 > j1)
	{
		highest = j2;
	}
	if (j3 > j1)
	{
		highest = j3;
	}
	if (j4 > j1)
	{
		highest = j4;
	}
	if (j5 > j1)
	{
		highest = j5;
	}
	return highest;
}
Last edited on
Try this, It is running but you need to check your logic a bit. I'll let you see what I'm talking about. Then lets see if you can solve this simple issue. Also I recommend not using so many if statements, try if, else if conditional statements.

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
#include <iostream>
#include <string>

using namespace std;

void getJudgeData(double& jscore, int& numjudge);
double calcScore(double& score, double& j1, double& j2, double& j3, double& j4, double& j5);

double getHighest(double& highest, double& j1, double& j2, double& j3, double& j4, double& j5);
double getLowest(double& lowest, double& j1, double& j2, double& j3, double& j4, double& j5);

double jtotal, jscore, j1, j2, j3, j4, j5, score, highest, lowest;
int numjudge;

int main()
{

	numjudge = 1;

	getJudgeData(jscore, numjudge);
	j1 = jscore;
	numjudge = numjudge + 1;

	getJudgeData(jscore, numjudge);
	j2 = jscore;
	numjudge = numjudge + 1;

	getJudgeData(jscore, numjudge);
	j3 = jscore;
	numjudge = numjudge + 1;

	getJudgeData(jscore, numjudge);
	j4 = jscore;
	numjudge = numjudge + 1;

	getJudgeData(jscore, numjudge);

	calcScore(score, j1, j2, j3, j4, j5);



	return 0;
}

void getJudgeData(double& jscore, int& numjudge)
{
	cout << "Input the score given by Judge " << numjudge << ".\n(score between 1-10)" << endl;
	cin >> jscore;
}

double calcScore(double& score, double& j1, double& j2, double& j3, double& j4, double& j5)
{
	double total;

	double findLowest(double, double, double, double, double);
	double findHighest(double, double, double, double, double);

	total = j1 + j2 + j3 + j4 + j5;
	score = total - highest - lowest;
	score = score / 3;
	return score;
}

double findLowest(double lowest, double score1, double score2, double score3, double score4, double score5)

{
	lowest = score1;
	if (score2 < score1)
	{
		lowest = score2;
	}
	if (score3 < score1)
	{
		lowest = score3;
	}
	if (score4 < score1)
	{
		lowest = score4;
	}
	if (score5 < score1)
	{
		lowest = score5;
	}
	return lowest;
}

double findHighest(double highest, double score1, double score2, double score3, double score4, double score5)
{
	highest = score1;
	if (score2 > score1)
	{
		highest = score2;
	}
	if (score3 > score1)
	{
		highest = score3;
	}
	if (score4 > score1)
	{
		highest = score4;
	}
	if (score5 > score1)
	{
		highest = score5;
	}
	return highest;
}
I've messed up with the variables, haha. I fixed them, but now "score" isn't outputting the judges score correctly.
Topic archived. No new replies allowed.