Debugging with a program

My frequencies in the end show up more then once. How do I fix my program so that cout << "Numeric Value " << foo[x] << " was entered " << tempcounter << " times.\n"; appears only once as opposed to more then once? Should I place it somewhere else in my program?

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

int main() {
    int numvalues;
    int uservalue;
    int minvalue;
    int maxvalue;
    int temp;
    int tempcounter;
    int tempcounterdetector;
   cout << "How many numeric values would you like to input? ";
   cin >> numvalues;


int foo[numvalues];


    for ( int x (0); x < numvalues; x++ )
    {
    cout << "Enter Numeric Value " << x+1 << ": ";
    cin >> uservalue;
    foo[x] = uservalue;

    }


/* now loop through array foo and sort to find min and max values */


//sort the array
for ( int x (0); x < numvalues; x++ )
{
  for ( int y (0); y < numvalues; y++ )
  {
    if(foo[x]<foo[y])
    {
     temp = foo[x];
     foo[x] = foo[y];
     foo[y] = temp;
    }
  }
}

// array is now sorted from lowest to highest number, now set min and max and display
    temp = numvalues - 1;
    cout << "\nThe Min Value is: " << foo[0];
    cout << "\nThe Max Value is: " << foo[temp];
    cout << "\n";

    //Now figure out amount times each value appears and display

for ( int x (0); x < numvalues; x++ )
{


tempcounter = 0;



  for ( int y (0); y < numvalues; y++ )
  {
    if(foo[x]==foo[y])
    {
     tempcounter = tempcounter + 1;
    }
  }


 cout << "Numeric Value " << foo[x] << " was entered " << tempcounter << " times.\n";

}




   return 0;
}
Topic archived. No new replies allowed.