Alex Jon Martin Walter
Alex Jon Martin Walter

Reputation: 109

I cannot figure out why my file is not writing out

#include<iostream>
#include<fstream>
using namespace std;
int main()
{

ifstream initialCost;
ofstream output;
output.open("output.txt");
initialCost.open("InitialCost.txt");
float csh1, af1, tr1, csh2, af2, tr2,tcsh1, tcsh2;

initialCost >> csh1 >> af1 >> tr1 >> csh2 >> af2 >> tr2;

tcsh1 =csh1+ (5*(csh1*tr1))+(5*af1);
tcsh2 =csh2+ (5*(csh2*tr2))+(5*af2);

cout<< "Initial House cost"<< '\t'
    << "Annual Fuel Cost" << '\t'
    << "Tax Rate" << '\t'
    << "Total Cost"<< '\n'
    << csh1 << '\t' << af1<< '\t' << tr1 << '\t' << tcsh1 << '\n'
    << csh2 << '\t' << af2<< '\t' << tr2 << '\t' << tcsh2 << '\n';



return 0;
}

My outputs are weird and I can't figure out why my second set of outputs are not working like the first. Also I need my outputs to write into the output file.

Upvotes: 0

Views: 72

Answers (2)

rcs
rcs

Reputation: 7227

Change

cout<< "Initial House cost"<< '\t'

to

output<< "Initial House cost"<< '\t'

Upvotes: 1

Some programmer dude
Some programmer dude

Reputation: 409472

I don't you meant to have commas in this line:

initialCost >> csh1 >> af1 >> tr1 >> csh2, af2, tr2;

And writing to a file is done just like writing to std::cout, both are output streams and works the same.

Upvotes: 0

Related Questions