droping lowest and highest to get average

This is whats required and I don't know arrays yet so that's kinda out. While loop does not execute with if ststement after cins and its all a little confusing right now could somebody share some light?


Requirements:
1. Input the contestant’s first name followed by the 5 judges’ scores. You do not know how many contestants there are. Design the loop so the loop terminates when you are finished entering contestants.
2. Input validation: Do not accept a judge’s score that is less than 1 or greater than 10. As each score is entered send the score to a function to test the score’s validity.
3. Use function calcAvgScore that has the contestant’s 5 scores as input parameters
a. returns the average score for that contestant.
b. Calls two functions, findLowest and findHighest which both accept the 5 scores as input parameters and return the lowest and highest scores, respectively.
4. Do not use global variables. All variables used in the functions must be passed as parameters or declared locally.
5. At the end of the program, display the winner and winning score (rounded to 2 decimal places).

And this is what I have come up with so far about 4 hrs lol.
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
#include <iostream>
#include <iomanip>
#include <cmath>



using namespace std;




int main()
{
    int quit;
    int i;
    string name;
    double score = 0.0;
    double total = 0.0;


while (quit != 2)
{
    cout << "Enter first name:" << endl;
    cin >> name;

    for (i = 0; i < total; i++)
    {
    cout << "Enter judge1 score: " << endl;
    cin >> score;
    if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }

    cout << "Enter judge2 score: " << endl;
    cin >> score;if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }


    cout << "Enter judge3 score: " << endl;
    cin >> score;
    if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }

    cout << "Enter judge4 score: " << endl;
    cin >> score;
    if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }

    cout << "Enter judge5 score: " << endl;
    cin >> score;
    if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }

    total += score;

}

    cout << "1 to continue or 2 to stop: " << endl;
    cin >> quit;



}


    total += score;
    cout << "Total:" << total << endl;







    return 0;

}
Last edited on
I am not sure how to store the strings unless I made a function that printed out every time it looped, and still why aren't if statements working in loops?
Revised I really buggered that up. Not sure how to store string maybe I should use a function to hold and display the values? A lil light here please?

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



using namespace std;




int main()
{
    int quit;
    int i;
    string name;
    double score = 0.0;
    double total = 0.0;


while (quit != 2)
{
    cout << "Enter first name: " << endl;
    cin >> name;

    for (i = 0; i < total; i++);
    cout << "Enter judge1 score: " << endl;
    cin >> score;
    {

    if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }

    cout << "Enter judge2 score: " << endl;
    cin >> score;
    if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }


    cout << "Enter judge3 score: " << endl;
    cin >> score;
    if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }

    cout << "Enter judge4 score: " << endl;
    cin >> score;
    if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }

    cout << "Enter judge5 score: " << endl;
    cin >> score;
    if (score < 1 || score > 10)
    {
        cout << "Try again" << endl;
        cin >> score;
    }



}
total += score;

    cout << "1 to continue or 2 to stop: " << endl;
    cin >> quit;



}


    total += score;
    cout << "Total:" << total << endl;



    return 0;

}
A little more progress but now when I run it this way. It only prints out judge once and it names it six. I did it like a video showed me I just don't know.

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



using namespace std;




int main()
{
    int quit;
    int i = 0;
    string name;
    double score[5];
    double total = 0.0;
    double maxScore = 0.0;
    double minScore = 0.0;
    double avg = 0.0;
    double tempScore = 0.0;


while (quit != 2)
{
    cout << "Enter first name: " << endl;
    cin >> name;

    for (i = 0; i < 5; i++);
    {
    cout << "Enter judge" << i + 1 << " score: " << endl;
    cin >> score[i];
    total += score[1];
    }

     avg + total / 12;

     maxScore = score[0];
     minScore = score[0];

     for ( int i= 0; i <= 5; i++ )
     {
         tempScore = score[0];
         if (tempScore < minScore)
         minScore = tempScore;
         if (tempScore > maxScore)
         maxScore = tempScore;
     }


}

      cout << "Score is: " << total << endl;


}




Ahhhhh more progress! but the yop for loop isn't counting or something?
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
#include <iostream>
#include <iomanip>
#include <cmath>



using namespace std;




int main()
{
    int quit;
    int i = 0;
    string name;
    double score[5];
    double total = 0.0;
    double maxScore = 0.0;
    double minScore = 0.0;
    double avg = 0.0;
    double tempScore = 0.0;


while (quit != 2)

{

    cout << "Enter first name: " << endl;
    cin >> name;



    for (int i = 0; i < 5; i++);
    {
    cout << "Enter judge" << i + 1 << " score: " << endl;
    cin >> score[i];
    }
     total += score[i];
     avg = total / 3;

     maxScore = score[0];
     minScore = score[0];

     for (int i= 0; i <= 5; i++)
     {
         tempScore = score[0];
         if (tempScore < minScore)
         minScore = tempScore;
         if (tempScore > maxScore)
         maxScore = tempScore;
     }

     cout << "Do you wish to continue? " << endl;
     cout << "Enter 1 to continue or 2 to end: " << endl;
     cin >> quit;
     if (quit == 1)
     {
         cout << "Thank You" << endl;
     }

}
      cout << "Score is: " << setprecision(2) <<  fixed << total << endl;
      cout << "Average is:" << setprecision(2) <<  fixed << avg << endl;


}






Topic archived. No new replies allowed.