#include <iostream.h>
#include <fstream.h> 
#include <math.h>
void main () 
{ 
	cout<<"**********************welcom*******************";
float n,j,q,d,h,t,i,m,f,b,v;
cout<<"\n num of eng = ";
cin >> j;
n=j ;
q=0;
d=0;
h=0;
t=0;
v =0 ;
for (i=1;i<=n;i++)
{  v = i;
    cout<<"\n\n ** Engineer ID  "<<v;
	cout<< "\n\n insert Salary =   ";
cin>> m;
d=m /(22) ;
h=d/(8) ;
cout<<"\n Leave : ";
cin>>f;
cout<< "\n Attend : ";
cin >> b;
t= f - b ;
 q= t * h ;
 cout<<"\n this day salary =  "<<q;
ofstream examplefile ("example.txt"); 
if (examplefile.is_open()) 
{ 
examplefile <<" engineer ID.\n"<<v;
examplefile<<"\n\n"<<q;
examplefile.close(); 
}
}
}

Recommended Answers

All 3 Replies

how i can make textfile not del data saved for every loop

ofstream opens the file in write mode, which truncates any existing data. You can specify ios::app as the second argument to ofstream's constructor. This will append without truncating.

p.s. I'm not in the mood to beat some sense into you, so I'll let everyone else snipe at your code and failure to use tags.

thnx that's will be only
ofstream examplefile ("example.txt", ios::app);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.