Invalid conversion from int (*) to int. How to fix?
Mar 12, 2016 at 9:58am UTC
Hi, I'm trying to write a code that finds all the perfect numbers within the given range and store it in an array, and then std::cout it. Here is my code:
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
#include <iostream>
int ifReturnPerfectOrZero(int iX)
{
int iSum = 0;
for (int iChecker = 1; iChecker < iX ; ++iChecker)
{
if (iX%iChecker == 0)
{
iSum = iSum + iChecker;
}
if (iX == iSum)
{
return iX;
}
}
return 0;
}
int main()
{
std::cout << "Enter limit (from zero to)" << std::endl;
int iLim = 0;
int Passer = 0;
std::cin >> iLim;
int iaPerfectNums[50];
for (int iX = 1; iX < iLim; ++iX)
{
Passer = ifReturnPerfectOrZero[iX];
iaPerfectNums[(iX-1)] = Passer;
}
std::cout << "The perfect numbers in the given range are:"
for (int iNum = 0; iNum < iLim; ++ iNum)
{
if (iaPerfectNums[iNum] != 0)
{
std::cout << iaPerfectNums[iNums] << std::endl;
}
}
}
I'm using code blocks IDE 13.12
P.S. the error is on line 33, the array part does not work for some reason (invalid conversion from int (*) to int)
Last edited on Mar 12, 2016 at 9:59am UTC
Mar 12, 2016 at 10:15am UTC
To call a function you need the round brackets.
Passer = ifReturnPerfectOrZero(iX);
Topic archived. No new replies allowed.