Finding Highest and Lowest

I have a class assignment where I read in scores from 5 users and I am supposed to
find the highest and lowest scores. I can't use arrays and I can only use functions and loops.

Here I get the scores from judges:
1
2
3
4
5
6
7
8
9
10
11
12
13
void getJudgeData(double &score)
{
	// Get a judge's score.
    cin >> score;


	// Validate the score.
	if(score < 0 || score > 10)
    {
        cout << "Invalid score" << endl;
    }

}


Next my teacher gives us a template for another function to calculate 5 scores:
1
2
3
4
5
6
7
double findLowest(double score1, double score2, double score3, double score4, double score5)

	              
{


}


I know I'm supposed to use a loop, but I'm still having trouble with loops and I don't know how to set it up to find the highest and lowest numbers.
Your getJudgeData function won't work correctly if you input an invalid score. Try tracing through it yourself (or use a debugger) and see what happens.

I'm not sure how using a loop would help you in the second case if you don't have an array. As for your actual problem statement there, how would you do it in real life? Try to implement something similar with your code.
so for the first case, is this any better?:
1
2
3
4
5
6
7
8
9
10
 int score;

   cout << "Enter a score between 1 and 10." << endl;
   cin  >> score;

   while (score < 0 || score > 10)
   {
       cout << "Invalid. Enter score between 1 and 10.\n";
       cin  >> score;
   }

The problem was that it was still accepting the values even though it said invalid.



As for the second case, I used a bunch of if statements. Can someone check if it'll work or is there a better way?:
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
double findLowest(double score1, double score2,
	              double score3, double score4,
				  double score5)
{
    double  lowest = score1;

    if(lowest > score2)
    {
        lowest = score2;
    }

    if(lowest > score3)
    {
        lowest = score3;
    }

    if(lowest > score4)
    {
        lowest = score4;
    }

    if(lowest > score5)
    {
        lowest = score5;
    }


}
closed account (E0p9LyTq)
To my non-expert eyes both functions look workable. :)
Topic archived. No new replies allowed.