how can i pass this info to next function?

This is just part of the code
FYI: read is void function!

1
2
3
4
5
6
7
 for (int i= 0; i <= 30; i++)
    {
        cout << i <<" : " << first[i] << " " << endl;
    }
    
    read(first, first[i])
Last edited on
Only thing I can think of would be references. Without seeing more code I really can't wrap my head around what you are doing to give you a better answer.
Here is rest:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main ()

{
    int first[30];
    srand( (unsigned int) time(NULL));
    
    for (int i=0 ; i <= 30; i++)
    {
        first[i] = rand() % 30 + 1; // The will create up to 30.

    }
    for (int i= 0; i <= 30; i++)
    {
        cout << i <<" : " << first[i] << " " << endl;
    }
      read(first, first[i])  
}


it show an error on read(first, first[i])

i want the number and element!
and how do you create a numbers line?

Last edited on
Well the error you are seeing is because you are trying to access the 'i' variable outside of its scope on Line 16. But to really help you we should see the function definition for "read()" and a copy paste of the specific error you are getting (in case there are more scoping issues) wouldn't hurt our efforts either.
Last edited on
I didn't even think about the fact that read() was out of scope to use i. I was focusing on read() because I thought he was wanting to know how to pass the data of read() to a function further down. Hence the references remark.
Last edited on
for (int i= 0; i <= 30; i++)

That code will read past the end of the array. Arrays start at 0 and end at n-1. Get used to this idiom:

for (int i= 0; i < 30; i++)

To solve the variable i being out of scope, declare & initialize it before line 12.

HTH
Topic archived. No new replies allowed.