Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m getting Linker errors when trying to run my code and can\'t find the source

ID: 3698348 • Letter: I

Question

I'm getting Linker errors when trying to run my code and can't find the source of the errors.

Main.cpp:

#pragma once
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include "Header.h"
using namespace std;


int main()
{

   ofstream outClientFile("employees.txt", ios::out);

  
   if (!outClientFile) // overloaded ! operator
   {
       cerr << "File could not be opened" << endl;
       exit(EXIT_FAILURE);
   }

   cout << "Enter the Employee ID, Number of hours worked and Pay rate." << endl
       << "Enter end-of-file to end input. ? ";

   int employeeid;
   float hoursworked;
   float payrate;

                  
   while (cin >> employeeid >> hoursworked >> payrate)
   {
       outClientFile << employeeid << ' ' << hoursworked << ' ' << payrate << endl;
       cout << "? ";
   }

   {

       ifstream inEmployeeFile("employees.txt", ios::in);

  
       if (!inEmployeeFile)
       {
           cerr << "File could not be opened" << endl;
           exit(EXIT_FAILURE);
       }

       int employeeid;
       float hoursworked;
       float payrate;

       cout << left << setw(10) << "Employee ID" << setw(13)
           << "Hours Worked" << "Pay Rate" << endl << fixed << showpoint;

       // display each record in file
       while (inEmployeeFile >> employeeid >> hoursworked >> payrate)
           outputLine(employeeid, hoursworked, payrate);
   }

  
   void outputLine(int employeeid, float hoursworked, float payrate);
   {
       cout << left << setw(10) << employeeid << setw(13) << hoursworked
           << setw(7) << setprecision(2) << right << payrate << endl;
   }

}

Explanation / Answer

Using below program with no errors

#pragma once
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;
void outputLine(int employeeid, float hoursworked, float payrate)
{
cout << left << setw(10) << employeeid << setw(13) << hoursworked
<< setw(7) << setprecision(2) << right << payrate << endl;
}   
int main()
{

ofstream outClientFile("employees.txt", ios::out);
  
if (!outClientFile) // overloaded ! operator
{
cerr << "File could not be opened" << endl;
exit(EXIT_FAILURE);
}
cout << "Enter the Employee ID, Number of hours worked and Pay rate." << endl
<< "Enter end-of-file to end input. ? ";
int employeeid;
float hoursworked;
float payrate;
  
while (cin >> employeeid >> hoursworked >> payrate)
{
outClientFile << employeeid << ' ' << hoursworked << ' ' << payrate << endl;
cout << "? ";
}
{

ifstream inEmployeeFile("employees.txt", ios::in);
  
if (!inEmployeeFile)
{
cerr << "File could not be opened" << endl;
exit(EXIT_FAILURE);
}
int employeeid;
float hoursworked;
float payrate;
cout << left << setw(10) << "Employee ID" << setw(13)
<< "Hours Worked" << "Pay Rate" << endl << fixed << showpoint;
// display each record in file
while (inEmployeeFile >> employeeid >> hoursworked >> payrate)
outputLine(employeeid, hoursworked, payrate);
}
  
return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote