#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main() {
   bool done = false;
   cout << setprecision(20) << endl;
    ifstream infile("in.txt");
    ifstream outfile("out.txt");
    while(!infile.eof()) {
           int sign = 1;
           double pi = 0;
           long n;
           infile >> n;
           for(long i = 1; i < n; i += 2) {
               pi += sign/(double)i;
               sign = -sign;
           }
           pi *= 4;
           cout << "value of pi for n = " << n << " is " << pi << endl;
       }
   return 0;
}
This reads from a file and prints to the console but I can't get the code to print to the outfile. I've tried doing
outfile<< "value of pi for n = " << n << " is " << pi << endl;
But that doesn't seem to work
 
    