conversion fro int to int*-error

Hello!
Please what is wrong here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
int Ave(int array_f[5], int& sm)
{

int k=0;

do
{

int e=1;
for (int i=2;i<sm;i++)
{
   if (sm%i==0)
       {
        e=0;break;
       }
}


if (e==1)
{
array_f[k]=sm; cout<<k<<" "<<sm<<" "<<array_f[k]<<endl;k=k+1;
}


sm=sm+1;
}  

               // do
while(k<5);
return k;


}              //function 

int main()
{
int x=128;
int array_m[5];
cout<<Ave(x);
return 0;
}



Compiler says: invalid conversion for int to int* ???

Many thanks!
Last edited on
int Ave(int array_f[5], int& sm)

the first parameter of this function expects an array to be passed, and an int value as a second argument, so at line 39 that should be :

cout << Ave( array_m, x );

and remove 5 in the array parameter declaration in your Ave () function :

int Ave ( int array_f[], int& sm ){ ... }
Hello!!!
Unbelievable!!!
It works now!

Just a question: i wrote return k; on the end of Ave function, but function actually writes out many other things (what I told by cout).

What is the real meaning of "function is returning k"?

Many thanks!
What is the real meaning of "function is returning k"?


it means the current function is terminated and a value is returned ( in your case the value 5 is returned )
to the caller function, or statement :

 
cout << Ave( array_m, x ); // the value returned by Ave() is 5, hence 5 is printed 


this would also work :
1
2
3
int var = Ave( array_m, x ); // store the value retuned by Ave to var

cout << var; // now print var ( will print 5 also ) 


http://www.cplusplus.com/doc/tutorial/functions/
Thanks, shadow fiend!!!
Topic archived. No new replies allowed.