Hello when I try to compile my program I get these errors:

1>funding6c.obj : error LNK2019: unresolved external symbol "void __cdecl ContributorSort(struct Contribution * const,int &)" (?ContributorSort@@YAXQAUContribution@@AAH@Z) referenced in function _main
1>C:\Users\Big Z\Desktop\program 6\Debug\program 6.exe : fatal error LNK1120: 1 unresolved externals

what could be causing this?

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

struct Contribution
{
	string name;
	double amount;
};

const int MAX = 25;

typedef Contribution BigSpender[MAX];

const string NAME_FILE = "names.txt";
const string CONTRIBUTION_FILE = "slush.txt";

void InitProgram( BigSpender );
void StringToLower (string& s);
void ContributorSearch (  bool& found, string searchVariable, int& donors,
						  int& location, BigSpender ContributionRec );
void ContributorSort( BigSpender ContributionRec, int& donors );

int main()
{
	string searchVariable; // what is being searched for

	int donors; // number of donors

	BigSpender ContributionRec;

		cout << "Welcome to the Big Spender Contributor Catalog Program."
		<< endl << endl;

		InitProgram(ContributionRec);

		ContributorSort ( ContributionRec, donors );

		cout << "Thank you for using the Big Spender Contributor"
			 << " Catalog Program." << endl << endl;
	return 0;
}

void InitProgram(BigSpender ContributionRec)
{
	ifstream nameLog, contributionLog;

	bool found;

	string searchVariable,
		   temp;

	int donors,
		location;
	double temp2;

	nameLog.open( NAME_FILE.c_str() ); // open file

	contributionLog.open( CONTRIBUTION_FILE.c_str() ); // open file

	if ( !nameLog ) // test if files opened
	{
		cout << "The file names.txt could not be opened. Please check the file"
			 << endl;
		exit (EXIT_FAILURE);
	}
	else if ( !contributionLog )
	{
		cout << "The file slush.txt could not be opened. Please check the file"
			 << endl;
		exit (EXIT_FAILURE);
	}

	nameLog >> donors;
	nameLog.ignore(80, '\n');
	
	for ( int i = 0; i < donors; i++ )
	{
		getline( nameLog, ContributionRec[i].name );

		ContributionRec[i].amount = 0.0;
	}
	nameLog.close();
	
	while ( contributionLog )
	{
		
		getline( contributionLog, temp );
		contributionLog >> temp2;
		contributionLog.ignore(80, '\n');

		ContributorSearch ( found, searchVariable, donors,
							 location, ContributionRec );
			if (found)
			{
				cout << left << setw(50) << ContributionRec[location].name;

				ContributionRec[location].amount = temp2 + ContributionRec[location].amount;
				cout << right << setw(10) << ContributionRec[location].amount
					<< endl;
			}
			else
			{
				cout << "Small Contributor";
			}


	}

	contributionLog.close();

	return;
}

void ContributorSearch ( bool& found, // true if we find it
						string searchVariable, // What we are looking for
						int& donors, // number of donors
						int& location, // location found at in the array
						BigSpender ContributionRec ) // array of 
{
	found = false;
	int count = 0; // start at 1st element

	while ( count < donors && !found )
		 // loop to search for the code in the codes array
	{
		if ( searchVariable != ContributionRec[count].name )
		{
			count++; // they do NOT match
		}
		else
		{
			found = true; // they do match

			location = count; // is index where found
		}
	}
	return;
}

void ContributorSort (int& donors, BigSpender ContributionRec )

// Sorts an array of book records into alphabetical order
// using the selection sort algorithm. The books array
// must be passed by reference here - why ?
// Assume here that data file is formatted to sort easily
// with no special handling except to convert 
// titles to all one case; here lower is used.

{	// SortBooks

	int
		start,		// index to first value in unsorted portion
		smallest,	// index to smallest value in unsorted portion
		current;	// used to scan array for "smallest" value
	// temporary storage for value during a swap 

	string
		copy1st,	// copies of original strings
		copy2nd,	// to be converted to all lower case
		tempSpender;
	// perform numbooks - 1 passes
	for (start = 0; start < (donors - 1); start++)
	{
    	smallest = start;
        
    	// scan unsorted part of array to find smallest title
   		for (current = (start + 1); current < donors; current++ )
		{
			// copy strings and convert copies to all lower case
			// why use copies ?
			copy1st = ContributionRec[current].name;
			copy2nd = ContributionRec[smallest].name;
			StringToLower (copy1st);
			StringToLower (copy2nd);

			if ( copy1st < copy2nd )
				smallest = current;
		}

		// perform one exchange of Contributor records if necessary
   		if (smallest != start)       
   		{                         
      		tempSpender = ContributionRec[start].name;
     		ContributionRec[start].name = ContributionRec[smallest].name;
     		ContributionRec[smallest].name = tempSpender;
   		}  

	}	// outer for loop

}    // ContributorSort

void StringToLower (string& s)

/* converts string s to all lower case */

{	// StringToLower

	int index,		// index into the string
		slen;		// length of the string

	slen = static_cast<int>(s.length());
	for (index = 0; index < slen; index++)
		s[index] = tolower(s[index]);

}	// StringToLower

Recommended Answers

All 3 Replies

The function definition must match the declaration exactly. That means order of parameters as well as type.

lines 25 and 144 do not match.

thanks!

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.