Can you please help me with this !
void code()
{
ofstream outp;
outp.open("result.txt");
ifstream inp;
inp.open("adding.txt");
double xo=0, yo=0, x=0,y=0;
while (inp >> x >> y) {
if (x==xo) {
yo = yo+y;
} else {
outp << xo << " " << yo << endl;
xo = x;
yo = y;
}
}
outp << xo << " " << yo << endl;
inp.close();
outp.close();
}
1 Like
If you check the results of your code, you will find mistake only in the first value
can you check please !
I was not claiming this code was bug free. That was just an idea showing how to proceed. You are free to change it as you need. I will look away way.
try this:
{
ofstream outp;
outp.open("result.txt");
double xo, yo, x, y;
ifstream inp;
inp.open("file0.txt");
inp >> xo >> yo;
yo = 0;
inp.close();
inp.open("file0.txt");
while (inp >> x >> y) {
if (x==xo) {
yo = yo+y;
} else {
outp << xo << " " << yo << endl;
xo = x;
yo = y;
}
}
outp << xo << " " << yo << endl;
inp.close();
outp.close();
}
1 Like
Thank you , ββ intelligent answer")
to open file we uses β> inputfile.open();
to close file we use β> inputfile.close();
to delete file we use -->> ??
remove(βfile.txtβ);
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.