aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-02-21 19:51:53 +0000
committerRossTheRoss <msattr@gmail.com>2019-02-21 19:51:53 +0000
commit1c4d830764f3b205463e7901b90a9c009850f44b (patch)
treefde14e01c647d10b2216755518607b8b9ecbd351
parentThank stackOverflow (diff)
downloadhomework-1c4d830764f3b205463e7901b90a9c009850f44b.tar
homework-1c4d830764f3b205463e7901b90a9c009850f44b.tar.gz
homework-1c4d830764f3b205463e7901b90a9c009850f44b.tar.bz2
homework-1c4d830764f3b205463e7901b90a9c009850f44b.tar.lz
homework-1c4d830764f3b205463e7901b90a9c009850f44b.tar.xz
homework-1c4d830764f3b205463e7901b90a9c009850f44b.tar.zst
homework-1c4d830764f3b205463e7901b90a9c009850f44b.zip
Fix my problems because I'm an idiot
-rw-r--r--ee1301/wk3/lab3/RootBabylonOG.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/ee1301/wk3/lab3/RootBabylonOG.cpp b/ee1301/wk3/lab3/RootBabylonOG.cpp
index 3abdd36..9972250 100644
--- a/ee1301/wk3/lab3/RootBabylonOG.cpp
+++ b/ee1301/wk3/lab3/RootBabylonOG.cpp
@@ -3,7 +3,7 @@
using namespace std;
double gennewGuess(double n, double old_guess) {
- double new_guess = ((old_guess+n) / old_guess) / 2;
+ double new_guess = ( old_guess + ( n / old_guess ) ) / 2;
return new_guess;
}
@@ -13,7 +13,7 @@ double BabylonRoot(double n) {
do {
guess = gennewGuess(n,guess);
cout << guess << endl;
- } while ((guess-real)/real>0.01); //Keep guessing unitl within 1% of the actual square root
+ } while (abs(guess-real)/real>0.05); //Keep guessing unitl within 5% of the actual square root
return guess;
}
@@ -23,11 +23,12 @@ int main () {
cin >> n;
if (n<=0) {
cout << "Please enter a valid input(Positive Integer)." << endl;
- return sqrt(-1);
+ return 2;
}
cout << "Guessing..." << endl;
double real=sqrt(n);
guess = BabylonRoot(n);
cout << "The Final Guess: " << guess << endl
<< "Actual Value: " << real << endl;
-}
+ return 0;
+} \ No newline at end of file