Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3027

need help with my source code but it wont complie and giving me errors

$
0
0
i tring to write a employee payroll code with functions and read data from the txt. file and also need help with bubble sort that sorts and displays starting from employees last name and calculations.

//txt file//
Hours Pay rate empID first name last name
40.0 10.00 A1234 Jane Adams
50.0 10.00 L8765 Mary Lincoln
25.5 10.85 W7654 Martha Washington
52.0 15.75 A9876 John Adams
45.0 25.00 W1235 George Washington
40.25 55.00 L9087 Abraham Lincoln
30.0 9.75 T9876 William Tell
42.5 12.50 M7654 Missy Muffett
30.0 10.00 P8765 Peter Piper

and here is my code
Code:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SZ = 55;
void tellUser();
int readData( string [], string [], string [], double [], double []);
int bubbleSort();
int outputScr();
int regular();
int overtime();
int grossPay();
int main()
{
      string firstname[SZ], lastname[SZ];
      string empids[SZ];
      double hours[SZ];
      double rates[SZ];
      ofstream outputFile;
      bool swapmade = false;
      bool screenonly = false;
      char yesno;
      int  i, numemp; 
      numemp = readData(firstname, lastname, empids, hours, rates);
      for (i = 0; i < numemp; i++)
      {
          cout << firstname[i] << lastname[i] << empids[i] <<  hours[i]
              << rates[i] << endl;
      }
      bubbleSort();
      outputScr();
      return 0;
}  //end main
/* bubbleSort()
 * sorts employees with theor last name snd displays in
 * screen and txt file
 */
int bubbleSort()
{
      cout << "sorting golfer\n";
      lastpos = numemp;
      do
      {
        lastpos--;
        swapmade = false;
        for ( i = 0; i < lastpos; i++)
        {
            swap(firstn[i], firstn[i+1]);
            swap(lastn[i], lastn[i+1]);
            swap(empID[i], empID[i+1]);
            swap(hrs[i], hrs[i+1]);
            swap(rate[i], rate[i+1]);
            swapmade - true;
        }
      } while(swapmade);
}
/* outputScr()
 * displays the employee payroll function to the screen and txt file
 */
int outputScr()
{
      cout <<"First  Last  Employee  Hours    Rate  Regular  Overtime  Gross\n";
      cout <<"Name    Name  Number    Worked  of Pay    Pay    Pay        Pay\n";
      cout <<"===================================================================\n";
               
      for ( i=0; i < numemp; i++)
      {
          cout<< setw(7) <<  firstn[i] << setw(13) << lastn[i];
          cout<< setw(12) << empID[i] << " " << setw(10) << hrs[i] << " ";
          cout<< setw(11) << rate[i] << " " << setw(11) << regular <<  " ";
          cout<< setw(11) << overtime << " " << setw(11) << grossPay << " \n";
          if (!screenonly)
          {
              outputFile << setw(7) << left << firstn[i] << " ";
              outputFile << setw(7) << left << lastn[i] << " ";
              outputFile << setw(4) << fixed << right << empID << " ";
              outputFile << setw(4) << fixed << right << hrs[i] << " ";
              outputFile << setw(4) << fixed << right << rate[i] << " \n";
          }
      }
      if (!screenonly)
      {
        outputFile.close(); cout << "Output file closed\n\n";}
} // end else
/* rellUser(0
 * tells about the program to the user
 */
void tellUser()
{
  cout <<"\nThis program reads a file called employees.txt,\n";
  cout <<"and it calculates the regular pay, overtime pay\n";
  cout <<"and grosspay and total for grosspay for each employee and\n";
  cout <<"sorts the from last name.\n";
  cout<<"output is written to the screen. \n\n"; //tell user what program does
}
/* regular()
 * calculates employees regular pay
 */
int regular()
{
  double  hours, rate;
  if(hours <= 40)
      grossPay = hours * rate;
}
/* overtime()
 * calculates employees overtime pay
 */
int  overtime()
{
  double hours, rate;
 // const int emp_hrs = 40;
 // const double emp_over = 1.5;
  if (hours >= 40)
    overtime = (hours - 40) * rate * 1.5;
}
/* grossPay()
 * calculates employees regular + overtime pay
 */
int  grossPay(double &)
{
  double  hours, rate;
  if (hours <= 40)
    grossPay = (hours * rate);
  else
    grossPay = ((hours - 40) * rate * 1.5);
}
/**************************************************
 * readData
 * firstname , lastname, empID, hours, rate of pay
 */
int readData(string firstn[], string lastn[], string empID[], double hrs[], double rate[])
{
    int numemp;
    ifstream inputFile;
    int i = 0;
    tellUser(); 
    // open file and read inputs from employees.txt
    inputFile.open("employees.txt");
    if (inputFile.fail())
    {
        cout << "Error opening file employees.txt \n\n";
        cout << "end of program\n\n";
    }
    else
    {
        while ((inputFile >> hrs[i]) && (i < SZ))
        {
          inputFile >> rate[i];
          inputFile >> empID[i];
          inputFile >> firstn[i];
          inputFile >> lastn[i];
          i++;
        } //end while
        cout << "There were " << i << " employess\n\n";
        numemp = i;
        inputFile.close();
        //************* close input file ****************//
        cout << "input file closed\n\n";
        cout << "Payroll being written to file payroll.txt\n"; //output function
        outputFile.open("payroll.txt"); // output file
        if (outputFile.fail())
        {
          screenonly = true;
          cout <<" output file did not open\n";
          cout <<" output file will only be sent to the screen\n";
        }
    }
}

here are the errors the are giving
Code:

payroll.cpp: In function ‘int bubbleSort()’:
payroll.cpp:52:8: error: ‘lastpos’ was not declared in this scope
payroll.cpp:52:18: error: ‘numemp’ was not declared in this scope
payroll.cpp:56:10: error: ‘swapmade’ was not declared in this scope
payroll.cpp:57:16: error: ‘i’ was not declared in this scope
payroll.cpp:59:18: error: ‘firstn’ was not declared in this scope
payroll.cpp:60:18: error: ‘lastn’ was not declared in this scope
payroll.cpp:61:18: error: ‘empID’ was not declared in this scope
payroll.cpp:62:18: error: ‘hrs’ was not declared in this scope
payroll.cpp:63:18: error: ‘rate’ was not declared in this scope
payroll.cpp:66:16: error: ‘swapmade’ was not declared in this scope
payroll.cpp: In function ‘int outputScr()’:
payroll.cpp:77:13: error: ‘i’ was not declared in this scope
payroll.cpp:77:22: error: ‘numemp’ was not declared in this scope
payroll.cpp:79:30: error: ‘firstn’ was not declared in this scope
payroll.cpp:79:55: error: ‘lastn’ was not declared in this scope
payroll.cpp:80:30: error: ‘empID’ was not declared in this scope
payroll.cpp:80:61: error: ‘hrs’ was not declared in this scope
payroll.cpp:81:30: error: ‘rate’ was not declared in this scope
payroll.cpp:83:16: error: ‘screenonly’ was not declared in this scope
payroll.cpp:85:15: error: ‘outputFile’ was not declared in this scope
payroll.cpp:92:12: error: ‘screenonly’ was not declared in this scope
payroll.cpp:94:10: error: ‘outputFile’ was not declared in this scope
payroll.cpp: In function ‘int regular()’:
payroll.cpp:114:26: error: assignment of function ‘int grossPay()’
payroll.cpp:114:26: error: cannot convert ‘double’ to ‘int()’ in assignment
payroll.cpp: In function ‘int overtime()’:
payroll.cpp:125:39: error: assignment of function ‘int overtime()’
payroll.cpp:125:39: error: cannot convert ‘double’ to ‘int()’ in assignment
payroll.cpp: In function ‘int grossPay(double&)’:
payroll.cpp:134:30: error: overloaded function with no contextual type information
payroll.cpp:136:43: error: overloaded function with no contextual type information
payroll.cpp: In function ‘int readData(std::string*, std::string*, std::string*, double*, double*)’:
payroll.cpp:171:9: error: ‘outputFile’ was not declared in this scope
payroll.cpp:174:12: error: ‘screenonly’ was not declared in this scope


Viewing all articles
Browse latest Browse all 3027

Latest Images

Trending Articles



Latest Images