function problem error i cant find

hi im reading a book and trying to solve one of the problem in it. my program isnt compiling
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
#include <iostream>
using namespace std;

void getJudgeData(float &);
void calcScore(float, float, float, float, float, float, float);
float findLowest (float, float, float, float, float);
float findHighest(float, float, float, float, float);


int main (int argc, char * const argv[]) {
	float data1,data2,data3,data4,data5,lowest,highest;
	
	getJudgeData(data1);
	getJudgeData(data2);
	getJudgeData(data3);
	getJudgeData(data4);
	getJudgeData(data5);
	
	lowest=findLowest(data1, data2, data3, data4, data5);
	highest=findHighest(data1, data2, data3, data4, data5);
	
	calcScore(data1, data2, data3, data4, data5, highest, lowest);
	
    return 0;
}

void getJudgeData(int &data){
	cout << "enter score :\n";
	cin>>data;
}

void caclScore(float score1, float score2, float score3, float score4, float score5,float highest,float lowest)
{
	cout << "the average of the score excluding the highest and lowest is "<<((score1+score2+score3+score4+score5)-(highest+lowest))/3;
}

float findLowest(float score1, float score2, float score3, float score4, float score5)
{
	if (score1<score2 && score1<score3 && score1<score4 && score1<score5) 
		{
			return score1;
		}
		else if(score2<score1 && score2<score3 && score2<score4 && score2<score5) 
		{
			return score2;
		}
		else if (score3<score1 && score3<score2 && score3<score4 && score3<score5)
		{
			return score3;
		}
		else if (score4<score1 && score4<score2 && score4<score3 && score4<score5) 
		{
			return score4;
		}
		else if (score5<score1 && score5<score2 && score5<score3 && score5<score4) 
		{
			return score5;
		}
}//compler give me error here   "control reaches end of non-void function"

float findHighest(float score1,float score2,float score3,float score4,float score5)
{
	if (score1>score2 && score1>score3 && score1>score4 && score1>score5 ) 
	{
		return score1;
	}
	else if(score2>score1 && score2>score3 && score2>score4 && score2>score5) 
	{
		return score2;
	}
	else if (score3>score1 && score3>score2 && score3>score4 && score3>score5) 
	{
		return score3;
	}
	else if (score4>score1 && score4>score2 && score4>score3 && score4>score5) 
	{
		return score4;
	}
	else if (score5>score1 && score5>score2 && score5>score3 && score5>score4)
	{
		return score5;
	}
}//compler give me error here  "control reaches end of non-void function" 

Last edited on
This means that if somehow none of those cases apply, your function doesn't return anything.
By the way, you're doing it in a bad way. Lots of rewriting the same code. You could do return max( max( max( max(score1, score2), score3), score4), score5); where max returns the greater of two numbers.
Last edited on
thanks, is there one for finding the least?
Topic archived. No new replies allowed.