8 Replies - 598 Views - Last Post: 28 March 2012 - 03:52 PM Rate Topic: -----

#1 Crusader175  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-March 12

Fatal error LNK 1120 and error LNK2019

Posted 28 March 2012 - 01:39 PM

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

void OpenFiles (ifstream& inFile, ofstream& outFile);
void ProcessClients (ifstream& inFile, ofstream& outFile, float hourlyRate);
void ProcessAClient (ifstream& inFile, ofstream& outFile, int& totalTime, float hourlyRate);
void GetandPrintAddress (ifstream& inFile, ofstream& outFile);
void PrintResults (int numberOfBills, int totalMintues, float hourlyRate);

int main()
{
	float hourlyRate;
	ifstream inFile;
	ofstream outFile;
	OpenFiles (inFile, outFile);
	if (!inFile||!outFile)
	{
		cout << "Error Opening Files" << endl;
		return 1;
	}
	cout << "Enter the hourly rate." << endl;
	cin >> hourlyRate;
	ProcessClients (inFile, outFile, hourlyRate);
	inFile.close();
	outFile.close();
	return 0;
}

void OpenFile (ifstream& inFile, ofstream& outFile)
{
	string inFileName;
	string outFileName;
	cout << "Enter the name of the input file." << endl;
	cin >> inFileName;
	inFile.open(inFileName.c_str());

	cout << "Enter the name of the output file." << endl;
	cin >> outFileName;
	outFile.open(outFileName.c_str());
	outFile << "Billing for clients of file " << inFileName << endl;
	outFile << fixed;
}

void ProcessClients (ifstream& inFile, ofstream& outFile, float hourlyRate)
{
	int totalTime= 0;
	int numberOfBills= 0;
	string name;
	getline (inFile, name);
	while (inFile)
	{
		outFile << name << endl;
		ProcessAClient (inFile, outFile, totalTime, hourlyRate);
		numberOfBills++;
		getline(inFile, name);
	}
	PrintResults (numberOfBills, totalTime, hourlyRate);
}

void PrintResults (int numberOfBills, int totalMinutes, float hourlyRate)
{
	float minutes= (float)totalMinutes;
	cout << "Total amount billed this month is " << minutes / 60.0 * hourlyRate << endl;
	cout << "Average time worked per job is " << minutes / float(numberOfBills) / 60.0 << endl;
	cout << "Average customer bill is " << minutes/ 60.0 *hourlyRate / float(numberOfBills) << endl;
}

void GetAndPrintAddress (ifstream& inFile, ofstream& outFile)
{
	string line;
	getline (inFile, line);
	outFile << line << endl;
	getline (inFile, line);
	outFile << line << endl << endl;
}

void ProcessAClient (ifstream& inFile, ofstream& outFile, int& totalTime, float hourlyRate)
{
	int time= 0;
	int hours;
	int minutes;
	float cost;
	int numberOfJobs;
	GetAndPrintAddress(inFile, outFile);
	inFile >> numberOfJobs;
	outFile << "Number of Jobs: " << numberOfJobs << endl;
	for (int count = 1; count <=numberOfJobs; count ++)
	{
		inFile >> hours >> minutes;
		time = hours *60 + minutes + time;
		outFile << "Job " << count << ": " << hours << "hours and " << minutes << "minutes " << endl;
	}
	cost= float(time) / 60.0 * hourlyRate;
	totalTime = totalTime + time;
	outFile << "Amount of Bill: $" << setprecision(2) << cost << endl << endl;
	string skip;
	getline (inFile, skip);
}



I keep receiving a fatal error LNK 1120 and error LNK2019 and I have no idea why it is messing up. Could someone please help me out here!

Thank you in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Fatal error LNK 1120 and error LNK2019

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,217
  • Joined: 23-August 08

Re: Fatal error LNK 1120 and error LNK2019

Posted 28 March 2012 - 02:04 PM

Prototypes and definitions must be exactly the same. Compare
Prototype:
void OpenFiles (ifstream& inFile, ofstream& outFile);

Definition:
void OpenFile (ifstream& inFile, ofstream& outFile)

Was This Post Helpful? 3
  • +
  • -

#3 Crusader175  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-March 12

Re: Fatal error LNK 1120 and error LNK2019

Posted 28 March 2012 - 02:44 PM

View PostJackOfAllTrades, on 28 March 2012 - 02:04 PM, said:

Prototypes and definitions must be exactly the same. Compare
Prototype:
void OpenFiles (ifstream& inFile, ofstream& outFile);

Definition:
void OpenFile (ifstream& inFile, ofstream& outFile)


Thank you very much! The program is running but the problem is it doesn't ask for file names first it goes straight to hourly rate and just doesn't run correctly.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,749
  • Joined: 25-December 09

Re: Fatal error LNK 1120 and error LNK2019

Posted 28 March 2012 - 02:46 PM

Post your current code.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 Crusader175  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-March 12

Re: Fatal error LNK 1120 and error LNK2019

Posted 28 March 2012 - 02:49 PM

View Postjimblumberg, on 28 March 2012 - 02:46 PM, said:

Post your current code.

Jim

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

void OpenFiles (ifstream& inFile, ofstream& outFile);
void ProcessClients (ifstream& inFile, ofstream& outFile, float hourlyRate);
void ProcessAClient (ifstream& inFile, ofstream& outFile, int& totalTime, float hourlyRate);
void GetandPrintAddress (ifstream& inFile, ofstream& outFile);
void PrintResults (int numberOfBills, int totalMintues, float hourlyRate);

int main()
{
	float hourlyRate;
	ifstream inFile;
	ofstream outFile;
	void OpenFiles (ifstream& inFile, ofstream& outFile);
	if (!inFile||!outFile)
	{
		cout << "Error Opening Files" << endl;
		return 1;
	}
	cout << "Enter the hourly rate." << endl;
	cin >> hourlyRate;
	ProcessClients (inFile, outFile, hourlyRate);
	inFile.close();
	outFile.close();
	return 0;
}

void OpenFile (ifstream& inFile, ofstream& outFile)
{
	string inFileName;
	string outFileName;
	cout << "Enter the name of the input file." << endl;
	cin >> inFileName;
	inFile.open(inFileName.c_str());

	cout << "Enter the name of the output file." << endl;
	cin >> outFileName;
	outFile.open(outFileName.c_str());
	outFile << "Billing for clients of file " << inFileName << endl;
	outFile << fixed;
}

void ProcessClients (ifstream& inFile, ofstream& outFile, float hourlyRate)
{
	int totalTime= 0;
	int numberOfBills= 0;
	string name;
	getline (inFile, name);
	while (inFile)
	{
		outFile << name << endl;
		ProcessAClient (inFile, outFile, totalTime, hourlyRate);
		numberOfBills++;
		getline(inFile, name);
	}
	PrintResults (numberOfBills, totalTime, hourlyRate);
}

void PrintResults (int numberOfBills, int totalMinutes, float hourlyRate)
{
	float minutes= (float)totalMinutes;
	cout << "Total amount billed this month is " << minutes / 60.0 * hourlyRate << endl;
	cout << "Average time worked per job is " << minutes / float(numberOfBills) / 60.0 << endl;
	cout << "Average customer bill is " << minutes/ 60.0 *hourlyRate / float(numberOfBills) << endl;
}

void GetAndPrintAddress (ifstream& inFile, ofstream& outFile)
{
	string line;
	getline (inFile, line);
	outFile << line << endl;
	getline (inFile, line);
	outFile << line << endl << endl;
}

void ProcessAClient (ifstream& inFile, ofstream& outFile, int& totalTime, float hourlyRate)
{
	int time= 0;
	int hours;
	int minutes;
	float cost;
	int numberOfJobs;
	GetAndPrintAddress(inFile, outFile);
	inFile >> numberOfJobs;
	outFile << "Number of Jobs: " << numberOfJobs << endl;
	for (int count = 1; count <=numberOfJobs; count ++)
	{
		inFile >> hours >> minutes;
		time = hours *60 + minutes + time;
		outFile << "Job " << count << ": " << hours << "hours and " << minutes << "minutes " << endl;
	}
	cost= float(time) / 60.0 * hourlyRate;
	totalTime = totalTime + time;
	outFile << "Amount of Bill: $" << setprecision(2) << cost << endl << endl;
	string skip;
	getline (inFile, skip);
}


Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,217
  • Joined: 23-August 08

Re: Fatal error LNK 1120 and error LNK2019

Posted 28 March 2012 - 02:54 PM

/facepalm

Read the tutorials on functions in my signature.
Was This Post Helpful? 2
  • +
  • -

#7 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,749
  • Joined: 25-December 09

Re: Fatal error LNK 1120 and error LNK2019

Posted 28 March 2012 - 03:00 PM

In the following snippet:
void OpenFiles (ifstream& inFile, ofstream& outFile);

int main()
{
	float hourlyRate;
	ifstream inFile;
	ofstream outFile;
	void OpenFiles (ifstream& inFile, ofstream& outFile);



You are defining two functions name OpenFiles. once before main (good), and then again inside main (bad). The last line in the above is not a function call it is a function definition.

You should read the tutorials linked below in my signature. Those tutorials should help you learn to use functions correctly.

Also You have never implemented a function with the name of OpenFiles(). You have named that implementation OpenFile(), notice the difference in spelling.

Jim
Was This Post Helpful? 0
  • +
  • -

#8 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Fatal error LNK 1120 and error LNK2019

Posted 28 March 2012 - 03:02 PM

View PostJackOfAllTrades, on 28 March 2012 - 04:04 PM, said:

Prototypes and definitions must be exactly the same.

Be careful of what you ask for. You just might get it.
:clap:
Was This Post Helpful? 0
  • +
  • -

#9 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Fatal error LNK 1120 and error LNK2019

Posted 28 March 2012 - 03:52 PM

@Crusader175: Jack said "prototypes and definitions". He didn't say anything about function calls.

The prototype is the 1-line "declaration" of the function, that you put before your main function.

The definition is the "implementation" of the function -- the code that defines exactly what the function does.

A function call is a line of code inside another function (in this case, in your main function) which "calls", or redirects the program flow to, some other function, for example your line 18.

A function prototype and the first line of the corresponding function definition should look the same, except for the semicolon at the end of the prototype. (Note: Technically, the prototype can omit parameter names and only give the types of the arguments, but that will only confuse you so you should ignore this note.) A function call looks similar to, but not exactly the same as the prototype or the definition.

A function prototype and a function definition start by specifying a return type. You should not mention the return type in the function call.

The argument list (the part in parentheses) of a function prototype and of a function definition consists of the type and name of each parameter. The argument list of a function call should contain only names (or literal/constant values) for each parameter.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1