// the output is coming out incorrectly. any suggestions?
//here is what i have

// Lab 4 read and calculation file/input
// This program will read the data in the input file
// used by grosspayMinustaxFileCode


#include <iostream>
#include <fstream>
using namespace std;


int main()
// this is the error message it displays if not working right to EXIT
{
ifstream inFile;
int employee = 1;// I am trying to get loop initialized
int exemptions, taxbracket; //the read other file cue
double hours, overtime, payrate, grosspay, netpay, rate, tax;


inFile.open("readGrosspayMinustax.cpp");
if (inFile.fail())
{
cerr << "error opening input file.\n\n";
system("pause");
exit(1);
}


//    cout << "Enter an integer: ";
while (inFile >> hours)
inFile >> payrate;


if (hours > 40)
{
overtime = hours - 40;
hours = 40;
}
else
overtime = 0;
grosspay = hours * payrate + overtime * payrate * 1.5;
cout << grosspay;
inFile >> taxbracket;
if (taxbracket == 1)
rate = .13;
else if (taxbracket == 2)
rate = .27;
else
rate = .35;
inFile >> exemptions;
{
tax = grosspay * (rate - .01 * exemptions);
netpay = grosspay - tax;
employee++;


cout << employee << hours << payrate << taxbracket << exemptions << endl;
cout << grosspay << tax << netpay;
}
inFile.close();
system("pause");
return 0;
}


/*\\ This is the read file where the fin.in file will derived data.


50.00 20.00 2 3
40.00 10.00 1 0
10.00 40.00 3 5
40.00 11.25 1 2


output 1.72093e-01521.6211e-3071.06159e+29222936723998968
1.72093e-015-6.88189e-0116.88206e-011Press any key to continue . . .*/

Edited 3 Years Ago by happygeek: fixed formatting

// the output is coming out incorrectly. any suggestions?
//here is what i have

// Lab 4 read and calculation file/input
// This program will read the data in the input file
// used by grosspayMinustaxFileCode

#include <iostream>
#include <fstream>
using namespace std;

int main()
// this is the error message it displays if not working right to EXIT
{
ifstream inFile;
int employee = 1;// I am trying to get loop initialized
int exemptions, taxbracket; //the read other file cue
double hours, overtime, payrate, grosspay, netpay, rate, tax;

inFile.open("readGrosspayMinustax.cpp");
if (inFile.fail())
{
cerr << "error opening input file.\n\n";
system("pause");
exit(1);
}

// cout << "Enter an integer: ";
while (inFile >> hours)
inFile >> payrate;

if (hours > 40)
{
overtime = hours - 40;
hours = 40;
}
else
overtime = 0;
grosspay = hours * payrate + overtime * payrate * 1.5;
cout << grosspay;
inFile >> taxbracket;
if (taxbracket == 1)
rate = .13;
else if (taxbracket == 2)
rate = .27;
else
rate = .35;
inFile >> exemptions;
{
tax = grosspay * (rate - .01 * exemptions);
netpay = grosspay - tax;
employee++;

cout << employee << hours << payrate << taxbracket << exemptions << endl;
cout << grosspay << tax << netpay;
}
inFile.close();
system("pause");
return 0;
}

/*\\ This is the read file where the fin.in file will derived data.

50.00 20.00 2 3
40.00 10.00 1 0
10.00 40.00 3 5
40.00 11.25 1 2

output 1.72093e-01521.6211e-3071.06159e+29222936723998968
1.72093e-015-6.88189e-0116.88206e-011Press any key to continue . . .*/

Code tags and formatting please. I see some issues. Let's start with these two lines:

while (inFile >> hours)
       inFile >> payrate;

Is this your entire while loop? If not, you need to put brackets around the code you want to repeat. I am guessing this is your main problem. These two lines will eat up your entire input file. Judging by the rest of your code, this is NOT what you want. You need to put brackets around the code you want to repeat in the while loop.

Second issue:

cout << employee << hours << payrate << taxbracket << exemptions << endl;
cout << grosspay << tax << netpay;

You need to put a tab or space or something between all of these different variables when you display them. As you have it now, it's hard to tell where one starts and one ends, so you can't really tell whether you are getting good output (you clearly are not here, but my point is that even if your program was working well, you wouldn't be able to make sense of the output since it all runs together).

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