In the C++ implementation of forward Euler, n is not defined in the second for loop and it should be nsteps instead. for (int i=1; i<=nsteps; i++) { t[i] = t[i-1] + h; y[i] = y[i-1] + h*f(y[i-1]); } for (int i=0; i<n; i++) { std::cout << t[i] << " " << y[i] << std::endl; }