943,937 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 13770
  • C++ RSS
Nov 9th, 2006
0

error C2064: term does not evaluate to a function taking 1 arguments

Expand Post »
I am new to C++. This is a homework problem. So if anyone gives up their time to help me it is greatly appreciated. I have perfect number program, I can get it to run if all my code is in the main. The assignment requests that I use a function to check numbers to see if they are perfect. I am getting an error when I use the function. I checked MSDN to find some help to no avail. So here is the code. Thanks again for any help!:cheesy:

  1. #include <iostream>
  2. using std::cin;
  3. using std::cout;
  4. using std::endl;
  5.  
  6. int perfect (int);
  7.  
  8. int main ()
  9. {
  10. int number = 1;
  11. int perfect = 0;
  12.  
  13. for(number=1; number < 1000; number++)
  14. {
  15. perfect = perfect(number); //here is where I call the function
  16. if (perfect > 0)
  17. {
  18. cout << perfect << " is a perfect number." << endl;
  19. cout << "It's factors are: ";
  20.  
  21. for ( int y = 1; y < perfect/2; y++ )
  22. {
  23. int divisor = perfect / y;
  24.  
  25. if ( perfect % y == 0 && y <= divisor)
  26. {
  27. cout << divisor << " " << y << endl;
  28. }
  29. } // ends factor perfect
  30. } // ends if perfect
  31. } // ends for to 1000
  32. }// ends main
  33.  
  34. int perfect (int counter) //here is where the function starts
  35. {
  36. int sum = 0;
  37. int divisor = 0;
  38. int y = 0;
  39. for (y = 1; y < counter/2; y++)
  40. {
  41. divisor = counter / y;
  42. if ( counter % y == 0 && y <= divisor)
  43. {
  44. int factors = y + divisor;
  45. sum += factors;
  46. }
  47. }
  48. if (sum - counter == counter)
  49. {
  50. return counter;
  51. }
  52. else
  53. return 0;
  54. }//ends function
Last edited by dmmckelv; Nov 9th, 2006 at 8:09 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
dmmckelv is offline Offline
33 posts
since Nov 2006
Nov 9th, 2006
0

Re: error C2064: term does not evaluate to a function taking 1 arguments

Hello,

The problem is, your function is called 'perfect' and your variable is too. You should change one of the two like so:

C++ Syntax (Toggle Plain Text)
  1.  
  2.  
  3. #include<iostream>
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7.  
  8. int perfect (int);
  9.  
  10. int main ()
  11. {
  12. int number = 1;
  13. int p = 0; //instead of perfect
  14. //etc....
Last edited by Nick Evan; Apr 2nd, 2010 at 5:15 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Nov 9th, 2006
0

Re: error C2064: term does not evaluate to a function taking 1 arguments

yep thats fine.. also make sure you return 0 when you declare int main(), otherwise declare void main()
The final program should look like this: (I changed the name of the function perfect(...) to perfect_function(...) and i added a return 0 at the end of main)
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using std::cin;
  3. using std::cout;
  4. using std::endl;
  5.  
  6. int perfect_function (int);
  7.  
  8. int main ()
  9. {
  10. int number = 1;
  11. int perfect = 0;
  12.  
  13. for(number=1; number < 1000; number++)
  14. {
  15. perfect = perfect_function(number); //here is where I call the function
  16. if (perfect > 0)
  17. {
  18. cout << perfect << " is a perfect number." << endl;
  19. cout << "It's factors are: ";
  20.  
  21. for ( int y = 1; y < perfect/2; y++ )
  22. {
  23. int divisor = perfect / y;
  24.  
  25. if ( perfect % y == 0 && y <= divisor)
  26. {
  27. cout << divisor << " " << y << endl;
  28. }
  29. } // ends factor perfect
  30. } // ends if perfect
  31. } // ends for to 1000
  32. return 0;
  33. }// ends main
  34.  
  35. int perfect_function (int counter) //here is where the function starts
  36. {
  37. int sum = 0;
  38. int divisor = 0;
  39. int y = 0;
  40. for (y = 1; y < counter/2; y++)
  41. {
  42. divisor = counter / y;
  43. if ( counter % y == 0 && y <= divisor)
  44. {
  45. int factors = y + divisor;
  46. sum += factors;
  47. }
  48. }
  49. if (sum - counter == counter)
  50. {
  51. return counter;
  52. }
  53. else
  54. return 0;
  55. }//ends function
Reputation Points: 13
Solved Threads: 2
Junior Poster in Training
may4life is offline Offline
57 posts
since Oct 2006
Nov 9th, 2006
0

Re: error C2064: term does not evaluate to a function taking 1 arguments

Quote ...
otherwise declare void main()
Nope. Just use return 0;
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Nov 9th, 2006
0

Re: error C2064: term does not evaluate to a function taking 1 arguments

Click to Expand / Collapse  Quote originally posted by may4life ...
... otherwise declare void main()
main() is an int function and officially cannot be be declared as void. In fact, some compilers flag a warning if void is used. Forget what M$ claims in their help. They are wrong.
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,739 posts
since May 2006
Nov 9th, 2006
0

Re: error C2064: term does not evaluate to a function taking 1 arguments

return 0 returns the number 0 (obviously.. hehe) to the Operating System. This is used to denote that the function main() was successfully completed. You can use void main() but as my friends above also noted, it is not recommended... so my final thoughts...DO use
C++ Syntax (Toggle Plain Text)
  1. int main()
  2. ...
  3. return 0; // to the OS
Reputation Points: 13
Solved Threads: 2
Junior Poster in Training
may4life is offline Offline
57 posts
since Oct 2006
Oct 1st, 2009
-1

Re: error C2064: term does not evaluate to a function taking 1 arguments

Click to Expand / Collapse  Quote originally posted by dmmckelv ...
perfect = perfect(number); //here is where I call the function
Well, the problem is that you have a variable (int perfect), as well as a function named perfect, which is not allowed, so you can either change the variable name, or the function name
Reputation Points: 4
Solved Threads: 1
Light Poster
venkat arun is offline Offline
28 posts
since Oct 2009
Oct 1st, 2009
0

Re: error C2064: term does not evaluate to a function taking 1 arguments

Well, the problem is that you have a variable (int perfect), as well as a function named perfect, which is not allowed, so you can either change the variable name, or the function name
How is that any different from what I said 3 years ago in this same thread?

Click to Expand / Collapse  Quote originally posted by Nick Evan ...
The problem is, your function is called 'perfect' and your variable is too. You should change one of the two
Lesson learned: Read thread first, reply later!
Last edited by Nick Evan; Apr 2nd, 2010 at 5:15 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: file I/O
Next Thread in C++ Forum Timeline: How to use library





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC