| | |
error C2064: term does not evaluate to a function taking 1 arguments
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 32
Reputation:
Solved Threads: 0
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:
c Syntax (Toggle Plain Text)
#include <iostream> using std::cin; using std::cout; using std::endl; int perfect (int); int main () { int number = 1; int perfect = 0; for(number=1; number < 1000; number++) { perfect = perfect(number); //here is where I call the function if (perfect > 0) { cout << perfect << " is a perfect number." << endl; cout << "It's factors are: "; for ( int y = 1; y < perfect/2; y++ ) { int divisor = perfect / y; if ( perfect % y == 0 && y <= divisor) { cout << divisor << " " << y << endl; } } // ends factor perfect } // ends if perfect } // ends for to 1000 }// ends main int perfect (int counter) //here is where the function starts { int sum = 0; int divisor = 0; int y = 0; for (y = 1; y < counter/2; y++) { divisor = counter / y; if ( counter % y == 0 && y <= divisor) { int factors = y + divisor; sum += factors; } } if (sum - counter == counter) { return counter; } else return 0; }//ends function
Last edited by dmmckelv; Nov 9th, 2006 at 8:09 am.
Hello,
The problem is, your function is called 'perfect' and your variable is too. You should change one of the two like so:
regards Niek
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)
#include<iostream> using std::cin; using std::cout; using std::endl; int perfect (int); int main () { int number = 1; int p = 0; //instead of perfect //etc....
regards Niek
•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Solved Threads: 2
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)
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)
#include <iostream> using std::cin; using std::cout; using std::endl; int perfect_function (int); int main () { int number = 1; int perfect = 0; for(number=1; number < 1000; number++) { perfect = perfect_function(number); //here is where I call the function if (perfect > 0) { cout << perfect << " is a perfect number." << endl; cout << "It's factors are: "; for ( int y = 1; y < perfect/2; y++ ) { int divisor = perfect / y; if ( perfect % y == 0 && y <= divisor) { cout << divisor << " " << y << endl; } } // ends factor perfect } // ends if perfect } // ends for to 1000 return 0; }// ends main int perfect_function (int counter) //here is where the function starts { int sum = 0; int divisor = 0; int y = 0; for (y = 1; y < counter/2; y++) { divisor = counter / y; if ( counter % y == 0 && y <= divisor) { int factors = y + divisor; sum += factors; } } if (sum - counter == counter) { return counter; } else return 0; }//ends function
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Oct 2006
Posts: 57
Reputation:
Solved Threads: 2
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)
int main() ... return 0; // to the OS
•
•
•
•
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
Lesson learned: Read thread first, reply later!
Last edited by niek_e; Oct 1st, 2009 at 6:04 am.
![]() |
Similar Threads
- Gettin C2064 error on a pretty simple program...Please help!! (C)
- error C2064: term does not evaluate to a function taking 1 arguments (C++)
Other Threads in the C++ Forum
- Previous Thread: file I/O
- Next Thread: How to use library
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






