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.

Member Avatar for iamthwee

Try organising your thoughts on paper first. If you know what flow charts are try drawing one.

[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.

[/De-cloak]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.