Hello all!
I've been working on an assignment for days and I just can't figure it out. I really wanted to figure it all out on my own but I am stumped. What I have to do is: generate 5000 random numbers between 1-53, then see how many times each number comes up. Supposed to look something like this:
number count
1 235
2 500
3 5
... ...
53
The most frequent generated number was:
The least frequent generated number was:
I created a for loop that runs to 5000 to populate my random_number array.
I created another array and loop to hold the number of times each number was generated.
What I can't figure out is how to read through the entire random_number array and transfer the count to my other array. I'm really lost. Any help would be much appreciated. My code is just about non-existant because I know it is something simple to link these two things together.
Thanks,
Pat
I've been working on an assignment for days and I just can't figure it out. I really wanted to figure it all out on my own but I am stumped. What I have to do is: generate 5000 random numbers between 1-53, then see how many times each number comes up. Supposed to look something like this:
number count
1 235
2 500
3 5
... ...
53
The most frequent generated number was:
The least frequent generated number was:
I created a for loop that runs to 5000 to populate my random_number array.
I created another array and loop to hold the number of times each number was generated.
What I can't figure out is how to read through the entire random_number array and transfer the count to my other array. I'm really lost. Any help would be much appreciated. My code is just about non-existant because I know it is something simple to link these two things together.
Code:
#include <iostream>
#include <stdlib.h>
#include <ctime>
using namespace std;
int main()
{
int random[5000] = {0}; //random number array
int number[53] = {0};
int x, y;
srand(time(0)); //random seed
for (x = 0; x < 5000; x++) {
lucky_number = 1 + rand() % 53;
random[x] = lucky_number;
}
for (y = 0; y < 53; y++) {
cout << y+1 << " " << number[y] << endl;
}
}
Thanks,
Pat