Hello, I am a beginner at C++ and need some help with arrays..

- I need to create a function that returns a random number from a sequence of 4 #s.

- Then I have to loop it 1000x and print the frequency of those 4 #s.

So far I have:

const int n=4, ntimes=1000;
int freq[n]={0};
short int seq[]={11,35,99,132};

and I understand I need to use:

rand(freq, n, ntimes);

and to output:

cout<<rndseq<<" occured "<<freq<<" times"<<endl;

Obviously, I havent had much time to work on it yet. I tried reading up on arrays but I did not find much on this specifically..

I just need someone to help me start off on the right foot. I'm not expecting anyone to fully write it for me. Just some pointers please. Much appreciated.

11 Years
Discussion Span
Last Post by Bench

[De-cloak] :eek:

Assuming that your array of random numbers is constant, then your 4 elements are always indexed by the numbers 0,1,2,3 .... that should make life pretty simple :) Start it out as a simple random-number picker for the numbers 0-3 and carry on from there.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.