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

int f (int n);

double e (double accuracy);

double exp (double expo, double exaccuracy);

Computation file

#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;
}

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;
			[B]result = f(arg1);[/B]

			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

... <<< this line is the error

I think its better to use code tags when posting code, not php tags.

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;
			[B]result = f (arg1);//THIS LINE IS THE ERROR[/B]

			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";
		}

Since you have a local variable called f, you can't call the function f(). Give them different names, like f_ret and func().

thanks :)

Heh, that was post 100 for him. I feel so honored. It's not reading the input.txt file though. Where do I put the input fine so my program can read it?

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

ifstream fin ("C:\\MyProgram\\input.txt");

the double-backslash is necessary, since the file location is a string (and '\\' is the escape character for a single backslash)

Thanks, but I already handed my project in... incorrectly. I probably got

probably (grade < 70)
{
cout << "Isuck because you failed" <<endl;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.