Linker error: undefined reference to inData()

This is my first time posting here so if I do not do it correctly please let me know. We are doing a group project for our final assignment, and our group leader posted this portion of the program with the message that when running the program she is getting an error message that says "Linker error: undefined reference to inData()" She is using CodeBlock for her editor. I think she is trying to declare functions that are not yet declared(If that makes sense. Thank you in advance

// FreindlyHardwareInventory.cpp

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;
int seqSearch(vector<int> itemNum, int& listSize, int itemNo);

void displayMenu(/*ofstream& outfile, vector<int> itemNum, vector<string> itemDesc, vector<int> pOrdered,
vector<int> pcsInStore, vector<int> numSold, vector<double> manufPrice,
vector<double> sellPrice, vector<int> reOrderNum, int& itemNo,
string& itemName, int& noOrdered, int& noSold, double& cost,
double& sellAt, printReport() not sure what is needed*/);

int inData(vector<int> itemNum, vector<string> itemDesc, vector<int> pOrdered,
vector<int> pcsInStore, vector<int> numSold, vector<double> manufPrice,
vector<double> sellPrice, int& itemNo, string& itemName, int psInStore, int& noOrdered, int& noSold,
double& cost, double& sellAt);

void itemSold(vector<int> itemNum, vector<string> itemDesc, vector<int> pOrdered,
vector<int> pcsInStore, vector<int> numSold, vector<double> manufPrice,
vector<double> sellPrice, int& itemNo, string& itemName, int& noOrdered, int& noSold,
double& cost, double& sellAt);

void printReport(ofstream& outfile, vector<int> itemNum, vector<string> itemDesc, vector<int> pOrdered,
vector<int> pcsInStore, vector<int> numSold, vector<double> manufPrice,
vector<double> sellPrice, int& itemNo, string& itemName, int& noOrdered,
int& noSold, double& cost, double& sellAt);


int main(int argc, char *argv[])
{
vector<int> invNumber;
vector<string> invDesc;
vector<int> piecesOrdered;
vector<int> piecesInStore;
vector<int> amtSold;
vector<double> manufacturePrice;
vector<double> sellAtPrice;
int itemNumber, pcOrdered, pInStore, numberSold;
double manuPrice, sellingPrice;
string name;
int listSize;
ofstream outfile;
outfile.open("FreindlyHardwareInventoryReport.txt");

//displayMenu(/* parameters needed*/); // functions won't work without being declared first

//calls function inData - says there is an undefined refernce to inData & not sure yet how to fix it
inData(invNumber, invDesc, piecesOrdered, piecesInStore, amtSold, manufacturePrice, sellAtPrice,
itemNumber, name, pcOrdered, pInStore, numberSold, manuPrice, sellingPrice);

system("PAUSE");
return EXIT_SUCCESS;


}

// function inData

int inData(vector<int> itemNum, vector<string> itemDesc, vector<int> pOrdered,
vector<int> pcsInStore, vector<int> numSold, vector<double> manufPrice,
vector<double> sellPrice, int& itemNo,
string& itemName, int& noOrdered, int psInStore, int& noSold, double& cost,
double& sellAt)
{
int choice = 0;
char answer;
bool newEntry = true;
int listSize;
int loc = 0;

listSize = itemNum.back() - 1;


while (newEntry)// loop for more entries
{
// choices for user
cout << "To enter an inventory item, press 1." << endl;
cout << "To enter an item as sold, press 2." << endl;
cout << "To change the price of an existing inventory item, press 3." << endl;

cin >> choice;

// switch to determine what kind of input
switch (choice)
{
case 1:// takes in all information for a new inventory item
cout << "Enter inventory item number." << endl;
cin >> itemNo;
seqSearch(itemNum, listSize, itemNo);
if (!-1)
{
itemNum.push_back(itemNo);
cout << "Enter item name." << endl;
cin >> itemName;
itemDesc.push_back(itemName);
cout << "Enter number of pieces ordered." << endl;
cin >> noOrdered;
pOrdered.push_back(noOrdered);
pcsInStore.push_back(noOrdered);
cout << "Enter the manufactures price." << endl;
cin >> cost;
manufPrice.push_back(cost);
sellAt = cost + (cost * .25);// determines selling price for a 25% mark-up

sellPrice.push_back(sellAt);
}
else // takes information for items already in inventory
{
cout << "Enter the number of pieces ordered." << endl;
cin >> noOrdered;
pOrdered[loc] = noOrdered;
pcsInStore[loc] += noOrdered;
cout << "Enter the manufactures price." << endl;
cin >> cost;
manufPrice[loc] = cost;
sellAt = cost + (cost * .25);
sellPrice[loc] = sellAt;
break;
}

case 2: // calls the SoldItem function
// void soldItem(itemNum, itemNo);
break;

case 3:// code to just change a price of an existing item
{
cout << "Enter the item number" << endl;
cin >> itemNo;
seqSearch(itemNum, listSize, itemNo);
cout << "Enter new manufacturers price." << endl;
cin >> cost;
manufPrice[loc] = cost;
sellAt = cost + (cost * .25);
sellPrice[loc] = sellAt;
break;
}

default:
cout << "You have not entered a valid choice." << endl;
}

// code to see if there is another new entry.
cout << "Do you want to enter another item number? Y or N" << endl;
cin >> answer;
if (answer == 'y' || answer == 'Y')
newEntry = true;
else
cout << "Do you want to print a report now?" << endl;
cin >> answer;
if (answer == 'y' || answer == 'Y')
newEntry = true;// just put in to try to run program will be removed
// printReport(outfile, itemNum, itemDesc, pOrdered, pcsInStore, numSold,
// manufPrice, sellPrice);// calls the printReport function
else
cout << "The program is closing now." << endl;
system("PAUSE");
return EXIT_SUCCESS;

}


}
// function description for sequential search of item numbers
int seqSearch(vector<int> itemNum, int& listSize, int itemNo)
{
int loc;
bool found = false;

loc = 0;

while (loc < listSize && !found)
if (itemNum[loc] == itemNo)
found = true;
else
loc++;
if (found)
return loc;
else
return -1;
}

Last edited on
This is some hideous code (don't take that the wrong way - all beginners write hideous code; what's important is that they recognise it and the next code is slightly less hideous). Having 14 parameters to one function makes it very hard to see where the problem is (and thus, makes it difficult to fix her errors - this is why we do not have 14 parameters into a function).

This in the declaration int psInStore, int& noOrdered does not match this in the definition int& noOrdered, int psInStore. The function being declared at the top does not match the one being defined later on, so when the linker goes looking for the function being called, that function does not exist.

The immediate solution is to make the definition match the declaration. The longer term solution is to not have functions with huge, unwieldy sets of input parameters.
Last edited on
Topic archived. No new replies allowed.