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

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 32
Reputation: dmmckelv is an unknown quantity at this point 
Solved Threads: 0
dmmckelv dmmckelv is offline Offline
Light Poster

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

 
0
  #1
Nov 9th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,899
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 302
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac

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

 
0
  #2
Nov 9th, 2006
Hello,

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

  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....

regards Niek
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 57
Reputation: may4life is an unknown quantity at this point 
Solved Threads: 2
may4life may4life is offline Offline
Junior Poster in Training

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

 
0
  #3
Nov 9th, 2006
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)
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,899
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 302
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac

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

 
0
  #4
Nov 9th, 2006
otherwise declare void main()
Nope. Just use return 0;
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

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

 
0
  #5
Nov 9th, 2006
Originally Posted by may4life View Post
... 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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 57
Reputation: may4life is an unknown quantity at this point 
Solved Threads: 2
may4life may4life is offline Offline
Junior Poster in Training

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

 
0
  #6
Nov 9th, 2006
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
  1. int main()
  2. ...
  3. return 0; // to the OS
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 8
Reputation: venkat arun has a little shameless behaviour in the past 
Solved Threads: 0
venkat arun venkat arun is offline Offline
Newbie Poster

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

 
-1
  #7
Oct 1st, 2009
Originally Posted by dmmckelv View Post
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,899
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 302
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac

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

 
0
  #8
Oct 1st, 2009
Originally Posted by venkat arun View Post
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?

Originally Posted by niek_e View Post
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 niek_e; Oct 1st, 2009 at 6:04 am.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC