NZ joy NZ joy - 3 years ago 146
C++ Question

c++ not looping properly or writing properly

for (int i = 0; i < 5; i++)
{
cout << "Please enter the coordinates pair (x,y)" << endl;
cin >> x >> y;

}
outfs << x<<" "<<y<< endl;

cout << "The output was writting in the file points.txt" << endl;
outfs.close();





system("pause");
return 0;


}

thtas the code i used its supposed to loop and ask the user for the coordinates , then its supposed to take thiose coordinates and print it into the point.txt file . But right now it just loops and asks for the coordinates and only prints the last coordinates in the file . what should i do ?

Answer Source

seems to me that the loop should contain outfs as well like this.

    for (int i = 0; i < 5; i++)
{
    cout << "Please enter the coordinates pair (x,y)" << endl;
    cin >> x >> y;
    outfs << x<<" "<<y<< endl;
} 

But it's very unclear when you don't include the entire file in your problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download