-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrootTesterResidual.cpp
More file actions
43 lines (34 loc) · 986 Bytes
/
rootTesterResidual.cpp
File metadata and controls
43 lines (34 loc) · 986 Bytes
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
//========================================
//rootTesterResidual.cpp
// Code to test my second square root function.
//========================================
#include <iostream>
#include <cmath>
using namespace std;
double squareRoot(double x, double eps);
//=====================>> main << ==============
int main(void)
{
cout.precision(15); //resolution of digits shown
double x;
double eps;
cout<< "Input x and the desired residual [q to quit]:> ";
cin >>x;
cin >>eps;
while(not cin.fail())
{
//we have valid input, so give it a try
double root = squareRoot(x, eps);
cout << " squareRoot("<<x<<", " <<eps<<") = ";
cout <<root<<endl;
cout<<"sqrt(" <<x<< ") = " <<sqrt(x)<<endl;
cout<<"Difference = " << root-sqrt(x)<<endl;
cout<<"Residual = "<<root*root-x<<endl;
cout<<"===================================="<<endl;
cout<<"Input x and the desired residual [q to quit]:> ";
cin>>x;
cin>>eps;
}
cout<< "Thanks for playing!" <<endl;
return 0;
}