- #1

Demjan

- 1

- 0

**Summary:**Problem with Euler Method in C++

Hello, I have a very difficult problem for me (a beginner in programming) how to make the version of the euler method presented in c ++ with the void, float functions, so that the program will calculate from the data that I enter during the program.

Code:

```
#include<iostream>
#include <string>
using namespace std;
double f(double x, double y) { return x + y; }
int main()
{
double x0, y0, xn, h, yn, slope;
int i, n;
cout<<"Warunki początkowe: "<< endl;
cout<<"x0 = ";
cin>> x0;
cout<<"y0 = ";
cin >> y0;
cout<<"Enter calculation point: xn = ";
cin>>xn;
cout<<"Enter number of steps: ";
cin>> n;
h = (xn-x0)/n;
cout<<"\nx0\ty0\tslope\tyn\n";
cout<<"------------------------------\n";
for(i=0; i < n; i++)
{
nachyl = f(x0, y0);
yn = y0 + h * slope;
cout<< x0 <<"\t"<< y0 <<"\t"<< slope <<"\t"<< yn << endl;
y0 = yn;
x0 = x0+h;
}
cout<<"\nValue of y at x = "<< xn<< " is " << yn;
return 0;
}
```

Last edited by a moderator: