Clearing an array.

Hi there. I'm not 100% sure that the array is my problem but thats what i think it is. When i loop back to the top of my main code it seems the values from the previous loop are still being counted. Is there any way to solve 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream> 

using namespace std;

int main() 
          { 
          int x = 0;
          float score [100];
          int i = 0;
          float max = 0;
          float min = 100;
          float total = 0;
          char choice = 'y';
          
          while (choice == 'y')
          {
          system ("cls");

          cout << endl << "How many judges are judging the event?: ";
          cin >> x;

          for (i=0;i<x;i++)
              {
                    cout << endl << "Please enter a score: ";
                    cin >> score [i];
                    total = (total + score[i]);
              if (score[i] > max)
                  {
                  max = score[i];
                  }
              if (score[i] < min)
                  {
                  min = score[i];
                  }
                  }  
                      
              cout << endl << "The total of the counted scores is:  " << total - (max + min) << endl << endl;
              cout << endl << "---- The discounted scores were ----- " << endl;
              cout << endl << "Maximum score: " << max << endl;
              cout << "Minimum score: " << min << endl;
              cout << endl << "-------------------------------------" << endl;
              cout << endl << "The average of the counted scores is: " << (total - (max + min)) / (x - 2) << endl;
              cout << endl << "-------------------------------------" << endl;
              cout << endl << "Do you want to continue?: ";
              cin >> choice;    
              } 
              
   system("pause"); 
   return 0;
}
everything but the array is your problem;) since min, max, total are keeping their value all the time.
Thanks for the hint mate :) I think i have it now but this is a total guess for me. It seems to work
anyway but would this be the correct way to clear the memory that the values were stored in?
No idea why i didn't have to assign a value of 0 to min but it didn't seem to work when i did.

1
2
3
4
5
6
7
8
 while (choice == 'y')
          {
          system ("cls");
          max = 0;
          total = 0;

          cout << endl << "How many judges are judging the event?: ";
          cin >> x;
Topic archived. No new replies allowed.