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?
#include <iostream>
usingnamespace 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;
}