I have the following C++ code: I am trying to understand why the code is compiling fine but it won't run in the exe, and I am trying to get an output file out of the result any clues to why this ight be happening? The error it mentions is ios::base something.
#include <cmath>
#include <iostream>
#include <fstream>
using namespace std;
float function(float j);
int main(){
int x_start =0, x_end = 20, dx, n =100;
dx = (x_end-x_start)/n;
float x[n], delta[n], deltax[n], dx1[n],y_1[n], y_0[n], derivative_f[n];
for (int i = 0; 100; i++){
x[i]= i*dx;
delta[i] = .0001 * x[i];
deltax[i] = x[i]+delta[i];
dx1[i] = deltax[i]-x[i];
y_1[i] = function(deltax[i]);
y_0[i] = function(x[i]);
derivative_f[i] = (y_1[i]-y_0[i])/dx1[i];
}
ofstream myfile;
myfile.open ("xsquaredCpp.dat", ios::out | ios::trunc );
for (int i;100;i++){
myfile << x[i] << " "<< derivative_f[i]<<"\n";
}
myfile.close();
return 0;
}
float function(float j){
float result;
result = pow(j,2);
return result;
}```
Aucun commentaire:
Enregistrer un commentaire