I'm studying arrays and can't figure out what I'm doing wrong.
I need to output an array with 8 random generated numbers between 5 and 25.
Before down voting my question : /, I tried looking already for similar questions on stackoverflow but most of them contain the use of algorithm's or different kinds of sort-techniques. I cannot use those technique's in my answer. It 'should' be easier to solve this.
Where is the problem in my code and why doesn't my random number generate a new number while i'm looping trough the array?
int table[8];
int random_number= rand() % 25 + 5;
for (int i=0; i<8; i++)
{
table[i] = random_number;
cout << table[i] << " ";
}
As I compile and run it, it gives me 8 times the same number, however I'm letting my array loop through each single index, while putting a random number in it? On paper this should work normally, right?
Is there anyone who can explain what I did wrong and why my loop is not working correctly?