Hello,
my homework assignment has me create a program that finds all numbers in an array that show up exactly 5 times. I am trying to solve this issue by making a frequency distribution via two loops and two arrays, but I am having trouble getting my loop to not recount a number it has already counted.
For example, if you enter ten 1’s into the “entered Numbers” array I want it to store a count of 10 in frequencyarray[1].
Instead it is storing
frequencyarray[0]10
frequencyarray[1]9
frequencyarray[2]8
ect...
#include <iostream>
usingnamespace std;
void enternumber(long[], int);
int main()
{ int size;
int numbers5=0;
cout << "How many numbers? ";
cin >>size;
long enteredNumbers[10000];
long frequencyArray[10000];
enternumber(enteredNumbers,size);
for (int x=0
; x<size;x++)
{
for ( int y=x; y<size; y++)
{
if (enteredNumbers[x] == enteredNumbers[y] ){ frequencyArray[x]++; }
}
}
for (int z=0; z<size;z++){cout<<frequencyArray[z];
if (frequencyArray[z]==5) {numbers5++;}
}
cout << "The number of values that show up 5 times is " << numbers5;
}
void enternumber(long enteredNumbers[],int f)
{
for ( int count=0; count<f; count++)
{
cout << "Enter an Integer: ";
cin >> enteredNumbers[count];
}
}
#include <iostream>
usingnamespace std;
void enternumber(long[], int);
int main()
{ int size;
int numbers5=0;
cout << "How many numbers? ";
cin >>size;
long enteredNumbers[10000];
long frequencyArray[10000];
enternumber(enteredNumbers,size);
for (int x=0
; x<size;x++){
if (enteredNumbers[x] == enteredNumbers[x] ){ frequencyArray[enteredNumbers[x]]++; }
}
for (int z=0; z<size;z++){cout<<frequencyArray[z];
if (frequencyArray[z]==5) {numbers5++;}
}
cout << "The number of values that show up 5 times is " << numbers5;
}
void enternumber(long enteredNumbers[],int f)
{
for ( int count=0; count<f; count++)
{
cout << "Enter an Integer: ";
cin >> enteredNumbers[count];
}
}
#include <iostream>
usingnamespace std;
void enternumber(long[], int);
int main()
{
int size;
int numbers5=0;
cout << "How many numbers? ";
cin >>size;
long enteredNumbers[10000];
long frequencyArray[10000];
enternumber(enteredNumbers,size);
for (int x=0; x<size; x++)
{
if (enteredNumbers[x] == enteredNumbers[x] )
{
frequencyArray[enteredNumbers[x]]++;
}
}
for (int z=0; z<size; z++)
{
cout<<frequencyArray[z];
if (frequencyArray[z]==5)
{
numbers5++;
}
}
cout << "The number of values that show up 5 times is " << numbers5;
}
void enternumber(long enteredNumbers[],int f)
{
for ( int count=0; count<f; count++)
{
cout << "Enter an Integer: ";
cin >> enteredNumbers[count];
}
}