Hi,
Im trying to figure out how to display a number from an array where it has been chosen by a random number.
I have got an array with 10 different numbers (always different when program is ran).
Each index is added with the previous index number
So lets say
0 = 10
1 = 30 (+20)
2 = 32 (+2)
3 = 40 (+8)
4 = 71 (+31)
5 = 76 (+5)
6 = 100 (+24)
7 = 152 (+52)
8 = 163 (+11)
9 = 200 (+37)
What I have done in addition to this is make the index number 9 a total value, so that a random number can be generated from 0-200.
Now
If the random number is 150, the program should display the value from index number 7 which is 152.
If the random number is 70, the program should display the value from index number 4 which is 71.
(I am looping this 10 times, so 10 random numbers are generated.)
This is where the problem comes in I can't seem to display the value from index 7.
Can someone point me in the right direction please. Would appreciate it a lot.
This is where I think the problem is coming but can't seem to figure it out
for (i=0; i < pop; i++)
{
randomno = (rand()%total);
cout<<"Random Number = "<<randomno<<endl;
for (j=0; j < pop; j++)
if (randomno > running_tot[i])
for (k=0; k < chro; k++)
{
par[i][k] = mosome[j][k];
j = pop + 1;
cout<<"Par ["<<i<<"] = "<<par[i];
cout<<endl;
}
}
(if the post is unclear, please say so and I will try elaborate abit more)
Thanks