Could someone help me with this problem I have? Basically I have to generate an array of 8 numbers and give all them a random value between 1-10. Then I have to generate an integer and give it a random value of 1-10. If the any number in that array is higher than the integer, it must be replaced with a value of 100. There must then be an output of the modified array. The array and output of the modified array must be done using a while loop.
I spent 3 hours over the course of 2 days to try and solve this problem and it is really frustrating considering it seem to be an easy question. Here is what my code looks like so far :
int main()
{
srand(time(0));
int a=rand()% 10+1;
int b[8];
int c[8];//scapegoat
int i=0;
cout<<a<<endl<<endl<<endl;
while(i<8)
{
b[i]=rand()% 10+1;
c[i]=b[i];
if(c[i]>a)
{
c[i]=100;
cout<<c[i]<<" ";
}
i++;
}
}
This code is the first I managed to churn out and it seem to be the best of all the methods that I tried, being able to convert the numbers to -1. However, it only shows how many numbers are -1 and not the whole array.