beginner c++ program "cannot be used as a function" problem


Can you explain me please what the problem here is and give me an example if its possible!!




#include <iostream>
#include <cmath>
using namespace std;



int main()
{

using namespace std;


double persons(10);
int max,min;

max=0;

int k;
int i;
int g;

for (i=0;i<10;i++)
{


cout<< "give me number of pancakes for person number:" << (i+1);



cin<< persons(i);

min=persons(0);

if (persons(i) > max)
{
max = persons(i);
}

else if (persons(i) < min)
{
min = persons(i);
k = i;
}



}

cout<< "Person number:" << k << "ate least number of pancakes.";

for (g=0;g<10;g++)
{

cout << "Person number " << (g+1) << "ate" << persons(g) << "pancakes";

}

return 0;




}
double persons(10);

No. persons is a variable, not a function. I think you meant to use [] instead of ().
You are declaring 'persons' as a variable but using it a function
http://www.cplusplus.com/doc/tutorial/variables/
http://www.cplusplus.com/doc/tutorial/functions/
could you please post the correct program because i've read the tutorials and i cant work it out.
double persons[10];
Last edited on
Indeed, when there's a "persons" and (something) after it, replace ( with [ and ) with ].

-Albatross
ok changed it like this and now only 1 error occurs:




#include <iostream>
#include <cmath>
using namespace std;



int main()
{

using namespace std;


double persons[10];
int max,min;

max=0;

int k;
int i;
int g;

for (i=0;i<10;i++)
{


cout<< "give me number of pancakes for person number:" << (i+1);



cin<< persons[(i)]; <--Here is the problem now " not math for operator" error

min=persons[(0)];

if (persons[(i)] > max)
{
max = persons[(i)];
}

else if (persons[(i)] < min)
{
min = persons[(i)];
k = i;
}

First of all, you can just do [i] and not [(i)].

The error is because you're using cin wrong. It should be >> and not <<.
Last edited on
Topic archived. No new replies allowed.