I am getting the following errors on my code below. Any help would be appreciated.

69 expected primary-expression before '>>' token 
71 `next' undeclared (first use this function) 
86`Total' undeclared (first use this function)
86  expected `;' before "Gross" 

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

using namespace std; 
int main() 
{ 

float totalTax = 0;  // declare total tax = 0
float totalGrossEarnings =0;  // declare total gross earnings = 0
float totalMedicalLevy = 0; // declare total medical levy = 0
float totalEarnings =0;  // declare total earnings =0
float taxPayable;
float netEarnings;
float medicalLevy;
float grossEarnings;
string employeeRecord[11];
int employeeNumber;
int hours=0;
int rate=0;

// declare input and output file streams 
ifstream infile; 
infile.open("earnings.txt", ios::in);

ofstream outfile; 
outfile.open("data.txt", ios::out);  // open the files for input and output 

// set format manipulators 
cout.setf(ios::fixed); 
cout << setprecision(2);


    outfile << setw(11)<< "employee Number" << setw(11)<<"gross Earnings" <<setw(11) << "tax Payable" << setw(11) <<"medical Levy" << setw (11) <<"net Earnings" <<endl;
   // write to outfile
    infile >>setw(11)>>employeeNumber>>setw(11)>>grossEarnings>>setw(11)>>taxPayable>>setw(11) 
    >>setw(11)>>netEarnings>>endl;     // read from infile

    while (infile>>next) // do more records
    {

          grossEarnings = (hours * rate);
          taxPayable = grossEarnings * 0.15;
          medicalLevy = grossEarnings * 0.01;
          netEarnings = grossEarnings - taxPayable - medicalLevy;
          totalGrossEarnings = totalGrossEarnings + grossEarnings;
          totalTax = totalTax + taxPayable;
          totalMedicalLevy = totalMedicalLevy + medicalLevy;
          totalEarnings = totalEarnings + netEarnings;

          }   
           while (infile>>next) // do more records
    {   
                    outfile << Total Gross Earnings
            outfile << Total tax;
            outfile << Total Medical Levy;
            outfile << Total Net Earnings< endl;
          }

    infile.close() ;
    outfile.close () ;

("PAUSE");
return 0;

}
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I would gladly help you with this.
- But I can't. Not because I lack C++ knowledge. No. The problem resides in your post formatting!

USE CODE TAGS.

I guess those numbers you write in front of the errors are line numbers. We can't see the line numbers of your code if there is no code tags.

If you want help, then make it easy for those who is going to help you :)

Edited 6 Years Ago by Excizted: added code tags x)

Mark your pasted code and press the (CODE) button.

Then your code will be surrounded with the code tags, and when you post it will be much easier for us to read:

int main()
{
    std::cout << "I am in code tags! :) And on line 3, obviously!!" << std::endl;
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

o.k. thanks!
I have been playing around with the code and when I compile & run it no longer displays errors but the box ( do not know what it is called) does not stay open.

what does that mean? sorry, I am not more programming savvy!

Ugh...

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

using namespace std; 
int main() { 

 float totalTax = 0; // declare total tax = 0
 float totalGrossEarnings =0; // declare total gross earnings = 0
 float totalMedicalLevy = 0; // declare total medical levy = 0
 float totalEarnings =0; // declare total earnings =0
 float taxPayable;
 float netEarnings;
 float medicalLevy;
 float grossEarnings;
 string employeeRecord[11];
 int employeeNumber;
 int hours=0;
 int rate=0;
 
 // declare input and output file streams 
 ifstream infile; 
 infile.open("earnings.txt", ios::in);
 
 ofstream outfile; 
 outfile.open("data.txt", ios::out); // open the files for input and output 
 
 // set format manipulators 
 cout.setf(ios::fixed); 
 cout << setprecision(2);


 outfile << setw(11)<< "employee Number" << setw(11)<<"gross Earnings" <<setw(11) << "tax Payable" << setw(11) <<"medical Levy" << setw (11) <<"net Earnings" <<endl;
// write to outfile 
infile >>setw(11)>>employeeNumber>>setw(11)>>grossEarnings>>setw(11)>>taxPayable>>setw(11) 
 >>setw(11)>>netEarnings>>endl; // read from infile

 while (infile>>next) // do more records
{

 grossEarnings = (hours * rate);
 taxPayable = grossEarnings * 0.15;
 medicalLevy = grossEarnings * 0.01;
 netEarnings = grossEarnings - taxPayable - medicalLevy;
 totalGrossEarnings = totalGrossEarnings + grossEarnings;
 totalTax = totalTax + taxPayable;
 totalMedicalLevy = totalMedicalLevy + medicalLevy;
 totalEarnings = totalEarnings + netEarnings;

} 

while (infile>>next) // do more records
{ 
 outfile << Total Gross Earnings
 outfile << Total tax;
 outfile << Total Medical Levy;
 outfile << Total Net Earnings< endl;
}

 infile.close() ;
 outfile.close () ;

 return 0;

}
}
This article has been dead for over six months. Start a new discussion instead.