My Program Wont append

[code]#include <iostream>
#include <fstream>

using namespace std;
int main()
{
int num=0;
int tot=0;

ofstream myfile;
myfile.open("payroll.txt");

for(int i=1;i<=7;i++)
{
cout<<"Please enter total payroll value for day "<<i<<endl;
cin>>num;

if (num>0)
{
tot=tot+num;
}
}

myfile<<tot<<endl;
myfile.open("payroll.txt",ios::app);

return 0;
}
/code]
You need to open for appending the first time:
1
2
ofstream myfile;
myfile.open("payroll.txt"); // here 


Not after output:
1
2
myfile<<tot<<endl;
myfile.open("payroll.txt",ios::app);
Thanks! Such a simple error!
Topic archived. No new replies allowed.