Program Outputs Abnormally Large Incorrect Value?

I am writing a program that asks the user to input 5 judge scores 1-10, drops the lowest and highest scores, finds the average of the three remaining scores, and outputs that value. Instead of outputting the average, my program outputs 2134765568.

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

using namespace std;

int score(int judgesScore)										//function to input score
{
	cout << "Please enter the judge's score: " << endl;			//asks user to input score
	cin >> judgesScore;											//input score
	do
	{if ((judgesScore > 10) || (judgesScore < 0))									//if the score is not between 0 and 10,		
	{
		cout << "The score must be between 0 and 10. Please enter the judge's score: " << endl;	//output that the score must be between 0 and 10
		cin >> judgesScore;																		//and input a new score
	}
	}while ((judgesScore > 10) || (judgesScore < 0));										//loop until a score between 0 and 10 is entered
	return judgesScore;																			//return judge's score
}

int findlowest(int score1, int score2, int score3, int score4, int score5, int lowest) //function to find lowest score
{	
	if (score1 < score2 && score1 < score3 && score1 < score4 && score1 < score5)				//if score1 is the lowest,
	{
		lowest = score1;																		//add its value to lowest
	}

	if (score2 < score1 && score2 < score3 && score2 < score4 && score2 < score5)				//if score2 is the lowest,
	{
		lowest = score2;																		//add its value to lowest
	}

	if (score3 < score1 && score3 < score2 && score3 < score4 && score3 < score5)				//if score3 is the lowest,
	{
		lowest = score3;																		//add its value to lowest
	}

	if (score4 < score1 && score4 < score2 && score4 < score3 && score4 < score5)				//if score4 is the lowest,
	{
		lowest = score4;																		//add its value to lowest
	}

	if (score5 < score1 && score5 < score2 && score5 < score3 && score5 < score4)				//if score5 is the lowest,
	{
		lowest = score5;																		//add its value to lowest
	}

	return lowest;
}

int findhighest(int score1, int score2, int score3, int score4, int score5, int highest)		//function to find the highest score
{
	if (score1 > score2 && score1 > score3 && score1 > score4 && score1 > score5)				//if score1 is the highest,
	{
		highest = score1;																		//add its value to highest
	}

	if (score2 > score1 && score2 > score3 && score2 > score4 && score2 > score5)				//if score2 is the highest,
	{
		highest = score2;																		//add its value to highest
	}

	if (score3 > score1 && score3 > score2 && score3 > score4 && score3 > score5)				//if score3 is the highest,
	{
		highest = score3;																		//add its value to highest
	}

	if (score4 > score1 && score4 > score2 && score4 > score3 && score4 > score5)				//if score4 is the highest,
	{
		highest = score4;																		//add its value to highest
	}

	if (score5 < score1 && score5 < score2 && score5 < score3 && score5 < score4)				//if score5 is the highest,
	{
		highest = score5;																		//add its value to highest
	}
	return highest;
}

int calcscore(int score1, int score2, int score3, int score4, int score5, int overallScore, int lowest, int highest)
{
	findlowest(score1, score2, score3, score4, score5, lowest);											//call findlowest function to find the lowest score
	findhighest(score1, score2, score3, score4, score5, highest);										//call findhighest function to find the highest score

	overallScore = ((score1 + score2 + score3 + score4 + score5 - lowest - highest)/3);					//calculate the average of the scores, after dropping the highest and lowest

	cout << "This contestant's overall score is " << overallScore << endl;						//output the final score

	return 0;
}

int main(int judgesScore, int score1, int score2, int score3, int score4, int score5, int overallScore, int lowest, int highest)
{  
	score(judgesScore);																			//call score function for the first judge's score
	score1 = judgesScore;																	//set score1 as the first judge's score
	score(judgesScore);																			//call score function for the second judge's score
	score2 = judgesScore;																	//set score2 as the second judge's score
	score(judgesScore);																			//call score function for the third judge's score
	score3 = judgesScore;																	//set score3 as the third judge's score
	score(judgesScore);																			//call score function for the fourth judge's score
	score4 = judgesScore;																	//set score4 as fourth judge's score
	score(judgesScore);																			//call score function for the fifth judge's score
	score5 = judgesScore;																	//set score5 as fifth judge's score
	calcscore(score1, score2, score3, score4, score5, overallScore, lowest, highest);			//call calcscore function to get the final score
	system("pause");																		//pause program to keep it open
}
Last edited on
Line 104. The variable overallScore has never been set to any value, so it's just whatever happens to be in the memory.

On line 103, you are calling a function that returns a value you are interested in, but you're not doing anything with it. You're throwing away the returned value.
Thank you! How would I set the value of overallScore in main to the value of overallScore in calcscore?
I changed the program so that the score is now output in the calcscore function and now the score is always 1.
score(judgesScore);
This does nothing. You are throwing away the returned value. Here is how to use the returned value from a function:
someValue = score(judgesScore);
Why are you passing a parameter into this function?

score1 = judgesScore;
This sets score1 to some random value, because you never set judgesScore.

int main(int judgesScore, int score1, int score2, int score3, int score4, int score5, int overallScore, int lowest, int highest)
This shouldn't even compile. What are you using to compile this? There are precisely two correct options, discussed here: https://isocpp.org/wiki/faq/newbie#main-returns-int
Last edited on
Topic archived. No new replies allowed.