| | |
error C2064: term does not evaluate to a function taking 1 arguments
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2006
Posts: 7
Reputation:
Solved Threads: 0
Hi, I'm using Microsoft Visual C++ and I keep getting this error referring to this one line in my main file. The line of error is in bold.
Header file
[php]
int f (int n);
double e (double accuracy);
double exp (double expo, double exaccuracy);
[/php]
Computation file
[php]
#include "wong_header.h"
int f(int n)
{
int t = 1;
while (n >= 1)
{
t = t * n--;
}
return t;
}
double e (double accuracy)
{
accuracy = accuracy - 1;
double fac = 1;
double ee = 0;
while (accuracy >= 1)
{
fac = fac * accuracy;
ee = ee + (1/(fac));
accuracy--;
}
return ee;
}
double exp (double expo, int exaccuracy)
{
exaccuracy = exaccuracy - 1;
double value;
double fact = 1;
double exo = 0;
while ((expo >=0)&&(exaccuracy >=1))
{
value = expo * exaccuracy;
fact = fact * exaccuracy;
exo = exo + (value/fact);
exaccuracy--;
}
return exo;
}
[/php]
main file
Can someone help me figure out what I'm doing wrong?
Header file
[php]
int f (int n);
double e (double accuracy);
double exp (double expo, double exaccuracy);
[/php]
Computation file
[php]
#include "wong_header.h"
int f(int n)
{
int t = 1;
while (n >= 1)
{
t = t * n--;
}
return t;
}
double e (double accuracy)
{
accuracy = accuracy - 1;
double fac = 1;
double ee = 0;
while (accuracy >= 1)
{
fac = fac * accuracy;
ee = ee + (1/(fac));
accuracy--;
}
return ee;
}
double exp (double expo, int exaccuracy)
{
exaccuracy = exaccuracy - 1;
double value;
double fact = 1;
double exo = 0;
while ((expo >=0)&&(exaccuracy >=1))
{
value = expo * exaccuracy;
fact = fact * exaccuracy;
exo = exo + (value/fact);
exaccuracy--;
}
return exo;
}
[/php]
main file
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>
using namespace std;
#include "wong_header.h"
int main()
{
string command;
int arg1;
double earg2;
double exarg4, exarg5;
int result;
double eresult, exresult;
ifstream fin ("input.txt"); //reads from file input.txt
if (!fin) //checks input file
{
cerr <<"Cannot open the file input.txt\n";
return 0;
}
ofstream fout("out.txt"); //output stream
if (!fout) //check if output file
{ //was opened successfully
cerr <<"Cannot open the file out.txt\n";
return 0;
}
while(!fin.eof()) //it will read line after line until the program ends
{
fin >> command;
int f = atoi (command.c_str());
if (command == "f")
{
fin >> arg1;
result = f(arg1);
cout << "factorial of " << arg1 << "= " << result << "\n";
fout << "factorial of " << arg1 << "= " << result << "\n";
}
else if (command == "!")
{
}
else if (command == "e")
{
fin >> earg2;
eresult = e(earg2);
cout << "e with the accuracy of " << earg2 << " is " << eresult<< "\n";
fout << "e with the accuracy of " << earg2 << " is " << eresult<< "\n";
}
else if (command == "exp")
{
fin >> exarg4, exarg5;
exresult = exp(exarg4, exarg5);
cout <<"The value of e^x with e being " <<exarg4<<" and x being " <<exarg5<< "is\n";
cout << exresult <<"\n";
fout <<"The value of e^x with e being " <<exarg4<<" and x being " <<exarg5<< "is\n";
fout << exresult <<"\n";
}
else
{
}
}
fin.close();
fout.close();
return 0;
}Can someone help me figure out what I'm doing wrong?
which line is in bold ? they all look bold to me. how about adding some comments that point to the line
I think its better to use code tags when posting code, not php tags.
... <<< this line is the error I think its better to use code tags when posting code, not php tags.
•
•
Join Date: Mar 2006
Posts: 7
Reputation:
Solved Threads: 0
Sorry, here it the main file again:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>
using namespace std;
#include "wong_header.h"
int main()
{
string command;
int arg1;
double earg2;
double exarg4, exarg5;
int result;
double eresult, exresult;
ifstream fin ("input.txt"); //reads from file input.txt
if (!fin) //checks input file
{
cerr <<"Cannot open the file input.txt\n";
return 0;
}
ofstream fout("out.txt"); //output stream
if (!fout) //check if output file
{ //was opened successfully
cerr <<"Cannot open the file out.txt\n";
return 0;
}
while(!fin.eof()) //it will read line after line until the program ends
{
fin >> command;
int f = atoi (command.c_str());
if (command == "f")
{
fin >> arg1;
result = f (arg1);//THIS LINE IS THE ERROR
cout << "factorial of " << arg1 << "= " << result << "\n";
fout << "factorial of " << arg1 << "= " << result << "\n";
}
else if (command == "!")
{
}
else if (command == "e")
{
fin >> earg2;
eresult = e(earg2);
cout << "e with the accuracy of " << earg2 << " is " << eresult<< "\n";
fout << "e with the accuracy of " << earg2 << " is " << eresult<< "\n";
}
else if (command == "exp")
{
fin >> exarg4, exarg5;
exresult = exp(exarg4, exarg5);
cout <<"The value of e^x with e being " <<exarg4<<" and x being " <<exarg5<< "is\n";
cout << exresult <<"\n";
fout <<"The value of e^x with e being " <<exarg4<<" and x being " <<exarg5<< "is\n";
fout << exresult <<"\n";
}
else
{
}
}
fin.close();
fout.close();
return 0;
}int f = atoi (command.c_str()); if (command == "f") { fin >> arg1; result = f (arg1);//THIS LINE IS THE ERROR cout << "factorial of " << arg1 << "= " << result << "\n"; fout << "factorial of " << arg1 << "= " << result << "\n"; }
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Generally, your input.txt should go in the same place as your executable. If for some reason, this is causing you problems, or you do not know where the executable is, refer to the complete path of the txt file explicitly, for example, in DOS/Windows, you'd use
the double-backslash is necessary, since the file location is a string (and '\\' is the escape character for a single backslash)
C++ Syntax (Toggle Plain Text)
ifstream fin ("C:\\MyProgram\\input.txt");
![]() |
Similar Threads
- error C2064: term does not evaluate to a function taking 1 arguments (C++)
- Gettin C2064 error on a pretty simple program...Please help!! (C)
Other Threads in the C++ Forum
- Previous Thread: C++ Random Numbers
- Next Thread: Overloading assignment operator
| Thread Tools | Search this Thread |
api array beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






