I'm very new to all of this so forgive me if I format incorrectly or ask a dumb question. Currently in school taking a C++ intro class and my prof has been no help with this. Writing a program to process an input file filled with various job titles and salary ranges (low to high) using three functions specified by the assignment (getData, getAvg, and getLowestAndHighestSalary). In building the program as I go in an attempt to catch any spelling errors/dumb mistakes as they appear, I noticed that as soon as I tried to reference the getData and getLowestAndHIghestSalary functions, it kicks back the error:
error LNK2019: unresolved external symbol "void __cdecl getData(class std::basic_ifstream<char,struct std::char_traits > &,class std::basic_string<char,struct std::char_traits,class std::allocator >,double,int &)" (?getData@@YAXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@NAAH@Z) referenced in function _main
followed by a LNK2020 error. My understanding is that these types of errors usually start a cascade so solving the first error will usually solve the rest, so I've focused on LNK2019. So far as I can tell, it's not recognizing my function definitions.
I've tried playing with settings, changing linker subsystem from console to windows and back, changing configuration type from application(.exe) to dynamic library(.dll) and back, as well as taking the function definitions and declarations to a header file and still no luck.
Anyone have any ideas on how to make the program recognize my functions?
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void getData(ifstream&, string, double, int&);
double getAverage(double&, double&);
void getLowestAndHighestAvgSalary(double&, int&, int&);
int main(void) {
ifstream inFile;
string jobs[20];
double salaryRange[20][2], avgSalary[20];
int numJobs = 0, lowest_index = 0, highest_index = 0;
char input;
getData(inFile, jobs[20], salaryRange[20][2], numJobs);
for (int i = 0; i < 19; i++) {
avgSalary[i] = getAverage(salaryRange[i][0], salaryRange[i][1]);
}
getLowestAndHighestAvgSalary(avgSalary[20], lowest_index, highest_index);
cout << "Would you like to output to console (a) or output file (b)?\n";
cin >> input;
if (input == 'a') {
for (int i = 0; i < 19; i++) {
cout << "The average salary of the " << jobs[i] << "is $" << avgSalary[i] <<endl;
}
cout << "\nThe lowest average salary is " << avgSalary[lowest_index] << " (" << jobs[lowest_index] << ")";
cout << "\nThe highest average salary is " << avgSalary[highest_index] << " (" << jobs[highest_index] << ")";
}
else if (input == 'b') {
ofstream outFile;
outFile.open("job_stat.txt");
for (int i = 0; i < 19; i++) {
outFile << "The average salary of the " << jobs[i] << "is $" << avgSalary[i] << endl;
}
outFile << "\nThe lowest average salary is " << avgSalary[lowest_index] << " (" << jobs[lowest_index] << ")";
outFile << "\nThe highest average salary is " << avgSalary[highest_index] << " (" << jobs[highest_index] << ")";
}
return 0;
}
void getData(ifstream& inFile, string jobs[], double salaryRange[][2], int& numJobs) {
inFile.open("job_salaries.txt");
for (int i = 0; i < 19; i++) {
if (inFile.eof()) {
break;
}
getline(inFile, jobs[i]);
inFile >> salaryRange[i][0];
inFile.ignore(3);
inFile >> salaryRange[i][1];
inFile.ignore(100, '\n');
numJobs = i;
}
}
double getAverage(double& lowSalary, double& highSalary) {
double avgSalary;
avgSalary = (lowSalary + highSalary) / 2;
return avgSalary;
}
void getLowestAndHighestAvgSalary(double avgSalary[], int& lowest_index, int& highest_index) {
highest_index = 0;
lowest_index = 0;
double temp = avgSalary[0];
for (int i = 0; i < 19; i++) {
if (avgSalary[i] > temp) {
highest_index = i;
}
}
for (int i = 0; i < 19; i++) {
if (avgSalary[i] < temp) {
lowest_index = i;
}
}
}