### My first algorithm

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 #include using namespace std; int main() { cout.precision(36); cout << "Anmol's Square Root Calculator!" << endl; cout << "" <> num; cout << "" << endl; do{ if (num <= 0) { cout<<""<> num; cout<<""<>count; do{ if (count <= 0) { cout<<""<> count; cout<<""<> playAgain; cout <<" "<> playAgain; cout <<" "<

Thats my algorithm program :D. It uses the babylonian algorithm to find the approximate square root of the number you enter. Can I get any feed back on what to improve and how?
Last edited on
First impression:

Use consistent indentation.
Using std::endl should only be used when you need to flush the output stream.
Refactoring code into functions would be good.
Move root calculation to separate function: something like: long double bsqrt(long double num, unsigned int count)
How do I move it into a separate function?
What do you mean flush the output stream?
Ill try using indentation and whitespace
 What do you mean flush the output stream?

http://www.cplusplus.com/reference/ios/endl/

For most situations, inserting a newline into the output stream is more appropriate (and a much less expensive operation on buffered streams.)

One could rewrite:
 12345 cout<<"Thank you for using a program made by Anmol Sethi!"<

as:
 12 cout << "Thank you for using a program made by Anmol Sethi!\n\n\n"; cout << "Hope you use it again!\n\n" ;

Or even as:
 12 cout << "Thank you for using a program made by Anmol Sethi!\n\n\n" "Hope you use it again!\n\n" ;
Oooo ok

So using escape sequences instead of endl?

Ill do that in my next code after this depending on what we learn in math next xD
Topic archived. No new replies allowed.