Answer keeps returning "nan"

Here is the question:
A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer’s final score is determined by dropping the highest and lowest score received, then aver- aging the three remaining scores. Write a program that uses this method to calculate a contestant’s score. It should include the following functions:

double getJudgeData() should ask the user for a judge’s score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five judges. 

void calcScore() should calculate and display the average of the three scores that remain after dropping the highest and lowest scores the performer received. This function should be called just once by main and should be passed the five scores. 
The last two functions, described below, should be called by calcScore, which uses the returned information to determine which of the scores to drop. 

double findLowest() should find and return the lowest of the five scores passed to it. 

double findHighest() should find and return the highest of the five scores passed to it.
Input Validation: Do not accept judge scores lower than 0 or higher than 10.

**I would really appreciate it if someone could help me :)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  #include <iostream>
#include <math.h>
using namespace std;

double getJudgeData1(double score1)
{

  cout << "Judge 1 please enter your score: ";
  cin >> score1;

  while (score1 < 0.0 || score1> 10.0)
    {
      cout << "The score entered must be between 0 and 10. Please enter again." << endl;
      cout << "\nJudge 1 please enter your score: ";
      cin >> score1;
    }
  return score1;
}

double getJudgeData2(double score2)
{

  cout << "Judge 2 please enter your score: ";
  cin >> score2;

  while (score2 < 0.0 || score2 > 10.0)
    {
      cout << "The score entered must be between 0 and 10. Please enter again." << endl;
      cout << "\nJudge 2 please enter your score: ";
      cin >> score2;
    }
  return score2;
}

double getJudgeData3(double score3)
{

  cout << "Judge 3 please enter your score: ";
  cin >> score3;

  while (score3 < 0.0 || score3 > 10.0)
    {
      cout << "The score entered must be between 0 and 10. Please enter again." << endl;
      cout << "\nJudge 3 please enter your score: ";
      cin >> score3;
    }
  return score3;
}

double getJudgeData4(double score4)
{

  cout << "Judge 4 please enter your score: ";
  cin >> score4;

  while (score4 < 0.0 || score4 > 10.0)
    {
      cout << "The score entered must be between 0 and 10. Please enter again." << endl;
      cout << "\nJudge 4 please enter your score: ";
      cin >> score4;
    }
  return score4;
}

double getJudgeData5(double score5)
{

  cout << "Judge 5 please enter your score: ";
  cin >> score5;

  while (score5 < 0.0 || score5 > 10.0)
    {
      cout << "The score entered must be between 0 and 10. Please enter again." << endl;
      cout << "\nJudge 5 please enter your score: ";
      cin >> score5;
    }
  return score5;
}

double findHighest()
{

  double score1, score2, score3, score4, score5;
  double highest = 0;

  if (score1 > score2 && score1 > score3 && score1 > score4 && score1 > score5)
    highest = score1;
  if (score2 > score1 && score2 > score3 && score2 > score4 && score2 > score5)
    highest = score2;
  if (score3 > score1 && score3 > score2 && score3 > score4 && score3 > score5)
    highest = score3;
  if (score4 > score1 && score4 > score2 && score4 > score3 && score4 > score5)
    highest = score4;
  if (score5 > score1 && score5 > score2 && score5 > score3 && score5 > score4)
    highest = score5;

  return highest;

}

double findLowest()
{

  double score1, score2, score3, score4, score5;
  double lowest = 0;

  if (score1 < score2 && score1 < score3 && score1 < score4 && score1 < score5)
    lowest = score1;
  if (score2 < score1 && score2 < score3 && score2 < score4 && score2 < score5)
    lowest = score2;
  if (score3 < score1 && score3 < score2 && score3 < score4 && score3 < score5)
    lowest = score3;
  if (score4 < score1 && score4 < score2 && score4 < score3 && score4 < score5)
    lowest = score4;
  if (score5 < score1 && score5 < score2 && score5 < score3 && score5 < score4)
    lowest = score5;

  return lowest;
}

void calcScore()
{

  double score1, score2, score3, score4, score5;
  double lowest;
  double highest;

  double findHighest(highest);
  double findLowest(lowest);
  double totalScore;
  double avgScore;

  totalScore = score1 + score2 + score3 + score4 + score5;
  avgScore = (totalScore - (highest+lowest))/3;

  cout << "\nThe contestant's average score is: " << avgScore << endl;
}

int main() {

  double score1, score2, score3, score4, score5;
  double lowest, highest;

  getJudgeData1(score1);
  getJudgeData2(score2);
  getJudgeData3(score3);
  getJudgeData4(score4);
  getJudgeData5(score5);

  calcScore();

  system("PAUSE");

  return 0;

}

1
2
double score1, score2, score3, score4, score5;
double lowest, highest;


These are uninitialised, which means junk values.

Looks like you need a review on functions.
http://www.cplusplus.com/doc/tutorial/functions/
A couple of quick comments, first you have a lot of code duplication, you really only need one getJudgeData() function, pass in variable that indicates what judge you're working on instead of the score variable. Then in the calling function make sure you actually use that return value.

If you've studied vectors or arrays then you should consider using one to hold the scores.

Your calcScore() function needs a parameter or two for the scores that you got from getJudgeData().


Topic archived. No new replies allowed.