#include <iostream>
usingnamespace 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;
}
}
"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: