invalid conversion from 'int*' to 'int'

Help me. I'm getting an error. I've tried everything I know, but I still can't get it to work.


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
42
43
44
45
46
47
48
49
#include <iostream>
using namespace std;
void fun (int ctr, int persons, int i, int lol);
int persons;

int main()
{
cout<<"Enter the number of persons eating the pie: ";
cin>>persons;
int eaten[persons],ctr[persons];

for (int i=0;i<persons;i++)
{
cout<<"Person "<<i+1<<": ";
cin>>eaten[i];
}

for (int i=0;i<persons;i++)
{
    ctr[i]=0;
for (int j=0;j<persons;j++)
{
if (eaten[i]>=eaten[j])
ctr[i]++;
}
if (ctr[i]==persons)
{
system ("cls");
cout<<"Person "<<i+1<<" ate the most."<<endl;
}
}
for (int i=persons-1;i>0;i--){
fun (ctr,persons,i,eaten);
}


system ("pause>0");
return 0;
}

void fun(int ctr,int persons, int i, int lol)
{
     for (int j=0;j<persons;j++)
{     
if (ctr[j]==i)
cout<<"Person "<<j+1<<" ate "<<lol[j]<<"."<<endl;
}

 }
Last edited on
closed account (zb0S216C)
"ctr" (not the formal parameter) is an array of "int". The expression "ctr;" will evaluate to an r-value address. Addresses in C++ are represented as pointers; "int*" in your case.

With the latter in mind, when you call "fun( )" on line 33, you're passing "ctr" to it which evaluates to a pointer; thus, an error.

To fix this, you'll need to either change the "ctr" parameter of "fun( )" to an "int*" or, select an element from "ctr". For example:

 
fun(ctr[0], ...);

Wazzak
Last edited on
Topic archived. No new replies allowed.