findLowest not returning the lowest. highest screwy too

This is making me crazy. The logic seems solid, but the findLowest and findHighest aren't returning the highest and lowest respectably.
For example, if I input judges' scores as 1,2,3,4,5 it tells me highest is lowest is 1 and highest is 2. If i input the scores as 1,3,4,5,2 it says highest is 3 and lowest is 1. If I input 5,4,3,2,1 highest is 5, lowest is 4. WTF am I doing wrong here?

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
  #include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

//Function prototypes
double getScore(double &, int &);
double calcAvgScore(double, double, double, double, double, double&);
double findLowest(double, double, double, double, double, double&);
double findHighest(double, double, double, double, double, double&);

int main()
{
    string contestant;
    ofstream inFile;
    ifstream readFile;
    int i = 1;
    char again;
    double score1, score2, score3, score4, score5,
    average, highest, lowest;
    
    cout << "*************************************************************\n"
    << "*-----------------------------------------------------------*\n"
    << "*                  Sinclair's Got Talent                    *\n"
    << "*************************************************************\n";
    
    inFile.open("scores.txt");
    do
    {
        cout << "Enter the name of the contestant: ";
        cin >> contestant;
        getScore(score1, i);
        getScore(score2, i);
        getScore(score3, i);
        getScore(score4, i);
        getScore(score5, i);
        calcAvgScore(score1, score2, score3, score4, score5, average);
        findLowest(score1, score2, score3, score4, score5, lowest);
        findHighest(score1, score2, score3, score4, score5, highest);
        cout << "\t Lowest score: " << lowest << endl;
        cout << "\tHighest score: " << highest << endl;
        
        inFile << contestant << ' ' << average << endl;
        
        cout << "More contestants? 'Y' or 'N': ";
        cin >> again;
    } while (again == 'y' || again == 'Y');
    inFile.close();
    
    readFile.open("scores.txt");
    
    string winnerTemp, winner;
    double total, test = 1;
    while (readFile >> winnerTemp >> total)
    {
        if (total > test)
        {
            test = total;
            winner = winnerTemp;
        }
    }
    
    cout << "\n";
    cout << "*************************************************************\n";
    cout << "\t\tAnd the winner is: " << winner << endl;
    cout << "*************************************************************\n";
    cout << "\n";
    
    readFile.close();
    
    return 0;
}

//Functions

double getScore(double &score, int &i)
{
    cout << "Enter Judge #" << i << "'s score: ";
    cin >> score;
    if (score < 0 || score > 10)
    {
        cout << "Please enter a valid score (1-10). Try again: ";
        cin >> score;
    }
    return i++;
}

double calcAvgScore(double score1, double score2, double score3,
                    double score4, double score5, double &average)
{
    double totalScore;
    totalScore = (score1 + score2 + score3 + score4 + score5);
    average = totalScore / 5;
    cout << "\tAverage score: " << average << endl;
    return average;
}

double findLowest(double score1, double score2, double score3,
                  double score4, double score5, double &lowest)
{
    lowest = score1;
    
    if (score2 < lowest)
        lowest = score2;
    else if (score3 < lowest)
        lowest = score3;
    else if (score4 < lowest)
        lowest = score4;
    else if (score5 < lowest)
        lowest = score5;
    
    return lowest;
}

double findHighest(double score1, double score2, double score3,
                   double score4, double score5, double &highest)
{
    highest = score1;
    
    if (score2 > highest)
        highest = score2;
    else if (score3 > highest)
        highest = score3;
    else if (score4 > highest)
        highest = score4;
    else if (score5 > highest)
        highest = score5;
    
    return highest;
}
originally I had something like this:
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
double findLowest(double score1, double score2, double score3,
	double score4, double score5, double &lowest)
{
	if ((score1 < score2) && (score1 < score3) && (score1 < score4) && (score1 < score5))
		lowest = score1;
	else if ((score2 < score1) && (score2 < score3) && (score2 < score4) && (score2 < score5))
		lowest = score2;
	else if ((score3 < score1) && (score3 < score2) && (score3 < score4) && (score3 < score5))
		lowest = score3;
	else if ((score4 < score1) && (score4 < score2) && (score4 < score3) && (score4 < score5))
		lowest = score4;
	else if ((score5 < score1) && (score5 < score2) && (score5 < score3) && (score5 < score4))
		lowest = score5;
	return lowest;
}

double findHighest(double score1, double score2, double score3,
	double score4, double score5, double &highest)
{
	if ((score1 > score2) && (score1 > score3) && (score1 > score4) && (score1 > score5))
		highest = score1;
	else if ((score2 > score1) && (score2 > score3) && (score2 > score4) && (score2 > score5))
		highest = score2;
	else if ((score3 > score1) && (score3 > score2) && (score3 > score4) && (score3 > score5))
		highest = score3;
	else if ((score4 > score1) && (score4 > score2) && (score4 > score3) && (score4 > score5))
		highest = score4;
	else if ((score5 > score1) && (score5 > score2) && (score5 > score3) && (score5 > score4))
		highest = score5;
	return highest;
}

but it would return strange values too and it looks kinda ugly.
1
2
3
4
5
6
7
8
9
10
11
12
    lowest = score1;

    if (score2 < lowest)
        lowest = score2;
    else if (score3 < lowest)
        lowest = score3;
    else if (score4 < lowest)
        lowest = score4;
    else if (score5 < lowest)
        lowest = score5;
    
    return lowest;


Consider what happens with 5, 4, 3, 2, 1.

Because score2 < score1, the algorithm will assign 4 to lowest. The function will therefore return 4.

Can you see why?

I think so, I took the else out of those statements so each on would test and execute. Now it's working fine. I also realized that the 'i' i used to hold judge number kept adding up the more contestants i entered so i defined that within the do-while loop. the finished product is so:
Please let me know if there are any other improvements i can make. (We don't start on arrays until next week, so none of that.)
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
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

//Function prototypes
double getScore(double &, int &);
double calcAvgScore(double, double, double, double, double, double&);
double findLowest(double, double, double, double, double, double&);
double findHighest(double, double, double, double, double, double&);

int main()
{
    string contestant;
    ofstream inFile;
    ifstream readFile;
    char again;
    double score1, score2, score3, score4, score5,
    average, highest, lowest;
    
    cout << "*************************************************************\n"
    << "*-----------------------------------------------------------*\n"
    << "*                  Sinclair's Got Talent                    *\n"
    << "*************************************************************\n";
    
    inFile.open("scores.txt");
    do
    {
        int i = 1;

        cout << "Enter the name of the contestant: ";
        cin >> contestant;
        getScore(score1, i);
        getScore(score2, i);
        getScore(score3, i);
        getScore(score4, i);
        getScore(score5, i);
        calcAvgScore(score1, score2, score3, score4, score5, average);
        findLowest(score1, score2, score3, score4, score5, lowest);
        findHighest(score1, score2, score3, score4, score5, highest);
        cout << "\t Lowest score: " << lowest << endl;
        cout << "\tHighest score: " << highest << endl;
        
        inFile << contestant << ' ' << average << endl;
        
        cout << "More contestants? 'Y' or 'N': ";
        cin >> again;
    } while (again == 'y' || again == 'Y');
    inFile.close();
    
    readFile.open("scores.txt");
    
    string winnerTemp, winner;
    double total, test = 1;
    while (readFile >> winnerTemp >> total)
    {
        if (total > test)
        {
            test = total;
            winner = winnerTemp;
        }
    }
    
    cout << "\n";
    cout << "************************************************************\n";
    cout << "\t\tAnd the winner is: " << winner << endl;
    cout << "************************************************************\n";
    cout << "\n";
    
    readFile.close();
    
    return 0;
}

//Functions

double getScore(double &score, int &i)
{
    cout << "Enter Judge #" << i << "'s score: ";
    cin >> score;
    if (score < 0 || score > 10)
    {
        cout << "Please enter a valid score (1-10). Try again: ";
        cin >> score;
    }
    return i++;
}

double calcAvgScore(double score1, double score2, double score3,
                    double score4, double score5, double &average)
{
    double totalScore;
    totalScore = (score1 + score2 + score3 + score4 + score5);
    average = totalScore / 5;
    cout << "\tAverage score: " << average << endl;
    return average;
}

double findLowest(double score1, double score2, double score3,
                  double score4, double score5, double &lowest)
{
    lowest = score1;
    
    if (score2 < lowest)
        lowest = score2;
    if (score3 < lowest)
        lowest = score3;
    if (score4 < lowest)
        lowest = score4;
    if (score5 < lowest)
        lowest = score5;
    
    return lowest;
}

double findHighest(double score1, double score2, double score3,
                   double score4, double score5, double &highest)
{
    highest = score1;
    
    if (score2 > highest)
        highest = score2;
    if (score3 > highest)
        highest = score3;
    if (score4 > highest)
        highest = score4;
    if (score5 > highest)
        highest = score5;
    
    return highest;
}
Topic archived. No new replies allowed.