First of all, use code tags. "[c o d e]// your code[/c o d e]" (without the spaces between the letters)
This works:
1 2
|
if (!inFile)
cout << "Error opening file.\n";
|
but you never "create" these files. You may want to have the user input a name of their choice using cin or something.
Assuming you have the .txt and .dat files pre-made, I think the problem may be:
while (!inFile.eof())
If it encounters an eof flag before you have even done anything it will exit the loop before it begins. You could test the stream before entering the loop but after creating it with something like this:
std::cout << " eofbit:"; print_state(stream); std::cout << '\n';
Also I'm a little surprised it compiles at all with so many syntax errors. Must be a miraculous combination of errors that messed it up so badly that the compiler now thinks it's right.
All of this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
outFile << fixed << showpoint << setprecision(2)
<< " Income Tax Report \n\n"
<< "First Name: " << f_name << "\n"
<< "Last Name: " << l_name << "\n\n"
<< setfill('.') << left << setw(31)
<< "Gross:"
<< setfill(' ') << right << setw(12)
<< gross << "\n"
<< "FICA:" << " $"
<< setfill(' ') << right << setw(10)
<< fica_amount << "\n"
<< setfill('.') << left << setw(31)
<< "Social Security Tax:"
<< setfill(' ') << right << setw(12)
<< social_amount << " %\n\n"
<< setfill('.') << left << setw(31)
<< "Taxed Amount:" << " $"
<< setfill(' ') << right << setw(10)
<< tax_amount << "\n"
<< setfill('.') << left << setw(31)
<< endl;
|
Is heavily problematic. First of all, it does nothing, let alone what you want it to do. You aren't doing anything to any stream because you aren't even trying to. I can't figure out why all of this does not throw a compiler error...
You even missing basic things like semi-colons on most lines. I assume that these are all supposed to be cout lines so you should
use cout
Before I look at too much more than that it might be useful if you take another look at your own program after reading the following reference section:
http://www.cplusplus.com/doc/tutorial/files/
and probably:
http://www.cplusplus.com/reference/fstream/ifstream/?kw=ifstream
Hopefully something there might help you,
Sean