When I run it, it prints out but the largest and lowest frequency's don't come out correctly?
#include <ctime>
#include <iostream>
#include <iomanip>
#include <array>
using namespace std;
void DisplayNum(int *x);
void DisplayData(int *x);
void FindMaxMin(int *x);
struct NUM
{
int n;
int freq;
};
NUM ALL[10];
int main()
{
srand(time(0));
int x[30];
for (int i = 0; i < 30; i++) //assign random numbers 0-9 to n
{
x[i] = rand() % 10;
}
DisplayNum(x); // show the random numbers assigned
cout << endl;
for (int i = 0; i < 10; i++) //set all numbers to integers from 0 - 9
{
ALL[i].n = i;
}
for (int i = 0; i < 30; i++)
{
ALL[x[i]].freq++;
}
DisplayData(x); //display the random numbers and their frequency
FindMaxMin(x);
system("PAUSE");
return 0;
}
void DisplayNum(int *x)
{
for (int i = 0; i < 30; i++)
{
cout << i[x] << " ";
}
}
void DisplayData(int *x)
{
cout << "NUMBER" << setw(20) << "FREQUENCY" << endl;
for (int i = 0; i < 30; i++)
{
cout << char(196);
}
cout << endl;
cout << setfill(' ');
cout << fixed << showpoint << setprecision(2);
for (int i = 0; i < 10; i++)
{
cout << left << setw(10) << ALL[i].n << right << setw(10) << ALL[i].freq;
cout << endl;
}
}
void FindMaxMin(int *x)
{
int max = 0;
int min = 9;
for (int i = 0; i < 10; i++)
{
if (ALL[i].freq > max)
{
max = ALL[i].freq;
if (x[i] == max)
{
cout << "Number(s) with the largest frequency of " << max << " is/are: " << x[i] << endl;
}
}
if(ALL[i].freq < min)
{
min = ALL[i].freq;
if (x[i] == min)
{
cout << "Number(s) with the lowest frequency of " << min << " is/are: " << x[i] << endl;
}
}
}
}