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

i have a problem with writing code i have a text file that has data 101 50000 22

ID: 3653959 • Letter: I

Question

i have a problem with writing code

i have a text file that has data

101 50000

225 70000

-93 15000

550 49000

333 93000

781 -11678

499 27654

680 55000

209 60000

0

with this datas i have to write it as

--------------------------------------------------------

101 50000.00 2500.00 12500.00 3825.00 31175.00

225 70000.00 3500.00 17500.00 5355.00 43645.00

-93 15000.00 invalid employee number

550 49000.00 2450.00 12250.00 3748.50 30551.50

333 93000.00 4650.00 23250.00 7144.50 57985.50

781 -11678.00 invalid gross pay

499 27654.00 1382.70 6913.50 2115.53 17242.27

680 55000.00 2750.00 13750.00 4207.50 34292.50

209 60000.00 3000.00 15000.00 4590.00 37410.00

----------------------------------------------------------

to solve this:

101(given)

50000(given)

2500(50000*5%)

12500(50000*25%)

3825(50000*7.65%)

31175(50000 - 2500 - 12500 - 3825=31175)

-------------------------------------------------------------

i have to use while loop with 0 as the sentinel

this is code that i wrote and i dont know how to add calculation part

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

using namespace std;

int main()

{
ifstream inputFile;
string filename;
double number,statetax,federaltax,fica;
int i=0;

cout << "PAYROLL REPORT" << endl;
cout << "Enter the name of the input file a:";
cin >> filename;
cout << "" << endl;
cout << "Employee"<<setw(10)<<"Gross Pay"<<setw(10)<<"Deductions"<<setw(8)<<"Net Pay"<<endl;
cout << "Number"<<setw(16)<<"State Tax"<<setw(13)<<"Federal Tax"<<setw(10)<<"FICA"<<endl;


inputFile.open("c://in5.txt");
if (inputFile)
{
while (inputFile >> number)
{
if (i%2 == 0)
{
cout << number << setw(8);

i++;

}

else if (i%2 == 1)
{

cout << number << endl;

i++;
}
}

inputFile.close();
}

else
cout << "Error opening the file." << endl;


return 0;
}

please help me!!

Explanation / Answer

please rate - thanks

you'll have to fix the headings, and you didn't specify which persent was which tax

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

using namespace std;

int main()

{
ifstream inputFile;
char filename[8];
int number;
double gross, statetax,federaltax,fica,net;
int i=0;

cout << "PAYROLL REPORT" << endl;
cout << "Enter the name of the input file a:";
cin >> filename;
cout << "" << endl;
inputFile.open(filename);

if (!inputFile)
    {
    cout << "Error opening the file." << endl;
    system("pause");
    return 0;
    }
cout << "Employee"<<setw(10)<<"Gross Pay"<<setw(10)<<"Deductions"<<setw(8)<<"Net Pay"<<endl;
cout << "Number"<<setw(16)<<"State Tax"<<setw(13)<<"Federal Tax"<<setw(10)<<"FICA"<<endl;
inputFile >> number;
while (number!=0)
{inputFile>>gross;
if(number<0)
    cout<<setw(6)<<number<<setw(10)<<setprecision(2)<<fixed<<gross<<"   invalid employee number ";
else if(gross<0)
     cout<<setw(6)<<number<<setw(10)<<setprecision(2)<<fixed<<gross<<"   invalid gross pay ";
else
    {statetax=gross*.05;
    federaltax=gross*.25;
    fica=gross*.0765;
    net=gross-statetax-federaltax-fica;
    cout<<setw(6)<<number<<setw(10)<<setprecision(2)<<fixed<<gross<<setw(10)<<statetax<<
        setw(10)<<federaltax<<setw(10)<<fica<<setw(10)<<net<<endl;
    }
inputFile >> number;
}
inputFile.close();
system("pause");
return 0;
}