Please support our C++ advertiser: Programming Forums
Views: 1072 | Replies: 2
![]() |
•
•
Join Date: Jul 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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:
and I understand I need to use:
rand(freq, n, ntimes);
and to output:
cout<<rndseq[i]<<" occured "<<freq[i]<<" 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.
- 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[i]<<" occured "<<freq[i]<<" 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.
Last edited by krayJ : Jul 27th, 2006 at 4:18 am.
[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]
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]
Last edited by Bench : Jul 27th, 2006 at 9:01 pm.
¿umop apisdn upside down? ![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode