how can i pass this info to next function?

Jan 30, 2014 at 12:17am
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 Jan 30, 2014 at 12:17am
Jan 30, 2014 at 12:23am
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.
Jan 30, 2014 at 12:33am
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 Jan 30, 2014 at 12:34am
Jan 30, 2014 at 12:51am
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 Jan 30, 2014 at 12:52am
Jan 30, 2014 at 1:24am
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 Jan 30, 2014 at 1:27am
Jan 30, 2014 at 6:16am
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.