squareroot function in basic

admin

Administrator
Staff member
well my school has proved to be even more retarded then ever. my assignment is to make a function that calculates the squareroot of a number. yes yes, sqr works perfectly fine but somehow actually making the function is what we need to know <img src="http://static.dreamincode.net/forums/style_emoticons/default/blink.gif" style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" /> <br /><br />anyways this is what i have so far and it comes pretty close on certain numbers but way off on others. im using these to help <br /><br /><a href="http://mathforum.org/dr.math/faq/faq.sqrt.by.hand.html" target="_blank">http://mathforum.org/dr.math/faq/faq.sqrt.by.hand.html</a><br /> and to check the sqr(number)<br /><br /><a href="http://www.math.com/students/calculators/source/square-root.htm" target="_blank">http://www.math.com/students/calculators/s...square-root.htm</a><br /><br /><br />a little more info, its to find sqr(number >=100 and <= 1000) and i used the if statements to generate a guess close to what the square should be although technically any random guess would work but then that would make it nearly impossible to follow and write out on paper since there would be two random numbers being generated lol <br /><br />From what my understanding is of the mathforum.org post is that i need to do another loop of averaging and division but i dont know how to add that into the code since it would be using the current value of squareroot. <br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> <br /><br />CLS<br /><br />RANDOMIZE TIMER<br /><br />number = INT(RND * (1000 - 100 + 1) + 100)<br /><br />IF number > 100 < 200 THEN<br />        x = 11<br />ELSEIF number >= 200 < 400 THEN<br />        x = 18<br />ELSEIF number >= 400 < 600 THEN<br />        x = 21<br />ELSEIF number >= 600 < 800 THEN<br />        x = 26<br />ELSEIF number >= 800 THEN<br />        x = 28<br />END IF<br /><br />square = squareroot(number, x)<br /><br />PRINT number<br />PRINT square<br /><br /><br /><br />FUNCTION squareroot (number, x)<br /><br />squareroot = ((number / ((((number / x) + x) / 2))))<br /><br />END FUNCTION<br /><br /><!--c2--></div><!--ec2--><br />
</div>
 
Back
Top