Bisection Method

So I have made run the program smoothly but how can I make the column of the error part move up by one step.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<iostream>
#include<cmath>
#include<iomanip>
#define f(x) (6)*(x)*(x)*(x) + (5)*(x)*(x) + (7)*(x) - 2
using namespace std;
int main()
{
	int i = 1;
	float a,b,c,e1,e2;
	double a1,b1,c1,d;

	cout<<"Welcome to the root solver."<<endl;
	cout<<"We are going to find the root of 6x^3+5x^2+7x-2=0 using Bisection Method."<<endl;
	cout<<"Enter the upper limit: ";cin>>a;
	cout<<"Enter the lower limit: ";cin>>b;
	cout<<"Enter the stopping error: ";cin>>e1;
	
	
	while (a<b)
	{
		cout<<"Your lower limit is larger than your upper limit. Please enter the correct limits."<<endl;
		cout<<"Enter the upper limit: ";cin>>a;
		cout<<"Enter the lower limit: ";cin>>b;
	}
	a1 = f(a);
	b1 = f(b);
	if (a1==0)
	{
		c = a;
	}
	else if (b1==0)
	{
		c = b;
	}
	else
	{
		while (a1*b1>0)
		{
			cout<<"The root is not found within the given limits. Please enter another limits."<<endl;
			cout<<"Enter another upper limit: ";cin>>a;
			cout<<"Enter another lower limit: ";cin>>b;
			while (a<b)
			{
				cout<<"Your lower limit is larger than your upper limit. Please enter the correct limits."<<endl;
				cout<<"Enter the upper limit: ";cin>>a;
				cout<<"Enter the lower limit: ";cin>>b;
			}
			a1 = f(a);
			b1 = f(b);
		}
		cout<<"_______________________________________________________________________________"<<endl;
		cout<<"Iteration\tXl\t Xu\t  Xr\t    Error"<<endl;
		cout<<"_______________________________________________________________________________"<<endl;
		cout<<"    "<<"0"<<"\t     "<<fixed<<setprecision(4)<<b<<"   "<<a<<endl;
		do
		{
			c = (a + b)/2;
			c1 = f(c);
			a1 = f(a);
			b1 = f(b);
			cout<<"    "<<i<<"\t     "<<fixed<<setprecision(4)<<b<<"   "<<a<<"    "<<fixed<<setprecision(8)<<c<<"  "<<fixed<<e2<<endl;
			if (c1==0)
			{
				cout<<"The root is "<<c<<"."<<endl;
			}
			else if (a1*c1<0)
			{
				b = c;
				e2 = a - b;
			}

			else
			{
				a = c;
				e2 = a - b;
			}
			i++;
		}while(fabs(e2)>e1);
	}
		cout<<"_______________________________________________________________________________"<<endl;
		cout<<endl;
		cout<<"The root is "<<fixed<<setprecision(8)<<c<<"."<<endl;
		system("pause");
		return 0;
}



If you run this code in the error part it will show a -1.#QNAN00 and after that is 0.5. I want to remove the -1.#QNAN00 and move the succeeding number up by one .
Topic archived. No new replies allowed.