Unresolved external errors

Hi there. I am trying to do a program for school but am getting 4 unresolved external errors having to do with my function call in the main. Please help for the sake of my grades.







//*************************************************************************************************************************************
// Program: Program 3
//
// Purpose: This program reads in sales data from a text file for all divisions in a company.
//
// Input: The program will read data in via text file
//
// Processing: The program will read in the data supplied via text file. It then will call a function getDivision to read in data for one division.
// The program will then call printDivision to output all of the data read in via a while loop. The function will also call addDivision to add all
// divisions sales amounts. Last, the function printCorpSummarry with print the total sales for each quarter.
//
// Output: The program will output each division with their data, as well as the otal sales per quarter, average sales per quarter, and the
// grand total, highest quarter, and lowest quarter.
//
// Author:
// Class: CS2020
// Semester: Fall 2018
//****************************************************************************************************************************************

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

//Structure definition for Corportation
struct Corporation
{
double totSalesQ1, totSalesQ2, totSalesQ3, totSalesQ4;
int numDivisions;
};

//Structure definition for Division
struct Division
{
string divName;
double Q1, Q2, Q3, Q4;

};

//Function Prototypes
void getDivision(Division, ifstream &infile);
void printDivision(Division);
void addDivision(Division, Corporation);
void printCorpSummarry(Corporation);



int main()
{
//Dynamically allocated space for structures and address to pointer
Corporation *corporatation = new Corporation;
Corporation *p2corp = corporatation; // removed &
Division *division = new Division;
Division *p2div = division; // removed &


//Read in data
ifstream infile;
infile.open("prog3.txt");

cout << "-------------------------------------------------------------------------------------------" << endl;
cout << " Stratus corp. Sales Report" << endl;
cout << " << endl;
cout << "------------------------------------------------------------------------------------------- " << endl;
cout << "Division" << setw(16) << "Q1" << setw(16) << "Q2" << setw(16) << "Q3" << setw(16) << "Q4" << endl;


//Loop to read in each line at a time and print it, as well as add to the corporation
if (infile.is_open())
{
int i = 0;
while (!infile.eof())
{
getDivision(*p2div, infile);
printDivision(*p2div);
addDivision(*p2div, *p2corp);

//Deallocate space
delete p2div;
p2div = nullptr;






}

}

else
cout << "File Not Found" << endl;
infile.close();
cout << "--------------------------------------------------------------------------------------------" << endl;

printCorpSummarry(*p2corp);
system("pause");
return 0;






}

//***************************************************************************************************************************
//
// Program 3
// Description: Sales Report Program
// Programmer:
// Class: CS2020 Fall 2018
// Function: getDivision
// Process: This function reads in 5 lines of data at a time and assigns it to the pointer
// Parameters: This function requires the pointer to the division to assign each line, and the file used to read data in
// Returns: Nothing
//
//***************************************************************************************************************************


void getDivision(Division* p2div, ifstream &infile)
{
getline(infile, p2div->divName);
infile >> p2div->Q1;
infile >> p2div->Q2;
infile >> p2div->Q3;
infile >> p2div->Q4;

}


//***************************************************************************************************************************
//
// Program 3
// Description: Sales Report Program
// Programmer: Jagon Ahlborn
// Class: CS2020 Fall 2018
// Function: printDivision
// Process: This function prints the 5 lines of data read in from the file
// Parameters: This function only requires the division pointer because that is all it needs to output
// Returns: Nothing
//
//***************************************************************************************************************************

void printDivision(Division* p2div)
{
cout << setw(15) << p2div->divName << setw(15) << p2div->Q1 << setw(15) << p2div->Q2 << setw(15) << p2div->Q3 << setw(15) << p2div->Q4 << endl;

}


//***************************************************************************************************************************
//
// Program 3
// Description: Sales Report Program
// Programmer:
// Class: CS2020 Fall 2018
// Function: addDivision
// Process: This function adds the division to a running total to be used in the corportation structure
// Parameters: This function requires the division pointer so it can add its components to the Corporation pointer
// Returns: Nothing
//
//***************************************************************************************************************************

void addDivision(Division* p2div, Corporation* p2corp)
{
p2corp->numDivisions += 1;

p2corp->totSalesQ1 = p2corp->totSalesQ1 + p2div->Q1;
p2corp->totSalesQ2 = p2corp->totSalesQ2 + p2div->Q2;
p2corp->totSalesQ3 = p2corp->totSalesQ3 + p2div->Q3;
p2corp->totSalesQ4 = p2corp->totSalesQ4 + p2div->Q4;



}


//***************************************************************************************************************************
//
// Program 3
// Description: Sales Report Program
// Programmer:
// Class: CS2020 Fall 2018
// Function: printCorpSummarry
// Process: This function outputs the corp totals, average quarterly sales, and the total sales. It also finds the highest
// grossing quarter, as well as the lowest grossing quarter
// Parameters: This function requires the corporation pointer to output its information
// Returns: Nothing
//
//***************************************************************************************************************************

void printCorpSummarry(Corporation* p2corp)
{
cout << "Corp Totals: " << setw(15) << p2corp->totSalesQ1 << setw(15) << p2corp->totSalesQ2 << setw(15) << p2corp->totSalesQ3 << setw(15) << p2corp->totSalesQ4 << endl;
cout << "Average Qtr Sales: " << setw(15) << p2corp->totSalesQ1 / p2corp->numDivisions << setw(15) << p2corp->totSalesQ2 / p2corp->numDivisions << setw(15) << p2corp->totSalesQ3 / p2corp->numDivisions << setw(15) << p2corp->totSalesQ4 / p2corp->numDivisions << endl;
cout << "" << endl;
cout << "Total Sales: " << setw(15) << p2corp->totSalesQ1 + p2corp->totSalesQ2 + p2corp->totSalesQ3 + p2corp->totSalesQ4 << endl;

double high = 0;
double low = 0;

while (int i = -1)
{
high = p2corp->totSalesQ1;

if (p2corp->totSalesQ2 > high)
{
high = p2corp->totSalesQ2;
}
else if (p2corp->totSalesQ3 > high)
{
high = p2corp->totSalesQ3;
}

else if(p2corp->totSalesQ4>high)
{
high = p2corp->totSalesQ4;
}

i = 1;
}


while (int i = -1)
{
low = p2corp->totSalesQ1;

if (p2corp->totSalesQ2 < low)
{
low = p2corp->totSalesQ2;
}
if (p2corp->totSalesQ3 < low)
{
low = p2corp->totSalesQ3;
}
if (p2corp->totSalesQ4 < low)
{
low = p2corp->totSalesQ4;
}

i = 1;
}

cout << "Corp High Qtr " << setw(15) << high;
cout << "Corp Low Qtr" << setw(15) << low;
}
code tags <> in the little editor thingy are appreciated in the future.

I see one issue. There is a thing called overloading in c++, where you can have 2 functions with the same name but different parameters, for example:
void foo(int x)
void foo(string s)

you are doing this inadvertently.

void getDivision(Division, ifstream &infile);


void getDivision(Division* p2div, ifstream &infile)

a division and a division pointer are NOT the same, so they don't match, and the compiler is confused. While it isn't required, it is very safe and self-defensive coding to just copy the function from the definition (where the code for it is) to make the prototype.

that would give you

void getDivision(Division* p2div, ifstream &infile); //named variables in the header are ok.
Got it, I did that for all of my functions and it works now! Thank you so much!!
Topic archived. No new replies allowed.