So i'm trying to write a program that finds the root of a number without formulas i.e. sqrt(x).
so far i have come up with
and in my calling program i have:Code:void Roots(double a, int b) { double x; switch(b) { case 2: for(x = 0; x < a; x = x + .001) { if ( a == x*x) { cout << "\n\tThe square root of " << a << " equals " << x; } } break; default: cout << "\n\tI haven't got to that switch yet"; } }
When i change that 2 to a 3, i get my default, but when i have it as a 2 to activate case 2, it prints nothing out. Why?Code:Root(5,2);
Also can anyone explain to me how you find rational roots of numbers i.e. 2^(5/2). I want to write a general function to do not only whole roots, but also rational roots. I have been reading this but i'm tired and its not clicking : Calculate square root without a calculator



LinkBack URL
About LinkBacks


