//Bisection method in C++
#include <iostream>
#include <string>
using namespace std;

float f(float x)
{return 3*x - tan(x);}

void bisect(float& a, float& b)
{
	float tol = 1.0e-5;
	float fa = f(a);
	float p = (a+b)/2;
	float fp = f(p);
	if((fp == 0) || ((b-a)/2 < tol))
		{cout << p << endl;
		cout << "Completed successfully" << endl;
		exit(0);}
	else
		{if(fa*fp > 0)
			a = p;
		else
			b = p;
		cout << p << endl;}	
}
int main()
{

	float a = 1.2;
	float b = 1.4;
	for(int i = 1; i <= 10000; i++)
		bisect(a, b);
	cout << "Procedure was unsuccessful" << endl;
}
