diff options
author | RossTheRoss <msattr@gmail.com> | 2019-02-21 19:51:53 +0000 |
---|---|---|
committer | RossTheRoss <msattr@gmail.com> | 2019-02-21 19:51:53 +0000 |
commit | 1c4d830764f3b205463e7901b90a9c009850f44b (patch) | |
tree | fde14e01c647d10b2216755518607b8b9ecbd351 /ee1301 | |
parent | Thank stackOverflow (diff) | |
download | homework-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
Diffstat (limited to 'ee1301')
-rw-r--r-- | ee1301/wk3/lab3/RootBabylonOG.cpp | 9 |
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 |