//#include "pch.h"
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double df(double x, double y)            //function for defining dy/dx
{
	double a = (x * x)/(y-1);                //Enter the Differential Equation to be solved
	return a;


}

int main()
{
	char ch, ch1;
	cout << "This is the Eullers Method calculator." << endl;
	cout << "Enter the differential equation to be solved in line 8 of the code." << endl;
	cout<<"have you entered the right equation? (Enter Y or N)" << endl;
	cin >> ch;
	ch1 = ch;
	while (ch1 == 'y' || ch1 == 'Y') {


		int n;
		double x0, y0, x, y, h;            
		cout.precision(4);            //sets number of decimal places to be displayed.
		cout.setf(ios::fixed);			//displays floating point numbers in standard notation
		cout << "\nEnter the initial values of x and y respectively:\n";        
		cin >> x0 >> y0;
		cout << "\nFor what value of x do you want to find the value of y\n";
		cin >> x;
		cout << "\nEnter the step size h:\n";            
		cin >> h;			//Step size of 0.0005 for percision
		cout << "x" << setw(19) << "y" << setw(19) << "  k  " << setw(16) << "y(i+1)\n";
		cout << "----------------------------------------------------------\n";
		while (fabs(x - x0) > 0.000001)
		{
			y = y0 + (h*df(x0, y0));            //calculate next y   
			cout << x0 << setw(16) << y0 << setw(16) << df(x0, y0) << setw(16) << y << endl;
			y0 = y;                    //pass this new y as y0 in the next iteration.
			x0 = x0 + h;                //calculate new x.
		}
		cout << x0 << setw(16) << y << endl;
		cout << "----------------------------------------------------------------------" << endl;
		cout << "y(" << x0 << ") = " << y << endl;
		break;
	}
	goto EndLable;
EndLable:
	cout << "----------------------------------------------------------------------" << endl;
	cout << "Program will end so that you may enter a different equation in line 8 of the program\n" << endl;

	return 0;
}