Hi, I signed up because I was having no luck finding an answer with this simply with google searches.
My code is in C++ it compiles, runs and outputs fine in Visual Studio 2008 on a PC. Ive put it in xcode, it compiles and runs fine, but does not seem to want to output any of my double variables to the text files. To test anything would output, I simply got it to output some text to the same file. Worked fine, just seems not to want to output variables, frustrating as it worked fine on VS2008.
Is there something I'm missing here?
My code is in C++ it compiles, runs and outputs fine in Visual Studio 2008 on a PC. Ive put it in xcode, it compiles and runs fine, but does not seem to want to output any of my double variables to the text files. To test anything would output, I simply got it to output some text to the same file. Worked fine, just seems not to want to output variables, frustrating as it worked fine on VS2008.
Is there something I'm missing here?
Code:
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int main()
{
cout << "Started" << endl;
//euler method
// declaring variables
double y0 = 0.1, y1 = 0, g = 0, h = 0.1, y00, y11, t = 0, en;
//energy
en = (1 - cos(y0) ) + ( ( y1*y1 ) / 2);
//output
ofstream euler("euler.txt");
ofstream write("write.txt");
write << y0 << endl;
euler << t << '\t' << y0 << '\t' << y1 << '\t' << en << endl;
for(int i = 0; i < 1000; i++){
//storing nth
y00 = y0;
y11 = y1;
//calculating n+1th
t += h;
y0 += ( h * y11 );
y1 -= ( ( h * y00 ) + ( h * g * y11 ) );
//energy
en = (1 - cos(y0) ) + ( ( y1*y1 ) / 2);
//output
euler << t << '\t' << y0 << '\t' << y1 << '\t' << en << endl;
}
cout << "Euler Method Complete" << endl;
}