3 Replies - 480 Views - Last Post: 18 August 2009 - 02:09 PM Rate Topic: -----

#1 pgaroots  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-August 09

How do I get this to work? Please Help!

Post icon  Posted 17 August 2009 - 09:12 PM

Module Module1
   Sub Main()
	  Dim value As Double

	  Console.Write("Enter # for A: ") 'Enter a #
	  value = Console.ReadLine() 'X = #

	  Console.WriteLine(SquareRoot(value))


   End Sub
   Dim X As Double
   Dim D As Double
   Dim Formula1 As Double
   Dim Formula2 As Double
  
   Function SquareRoot(ByVal A As Double)
	  If A > 0 Then X = A
	  Formula1 = (X * X - A) / (2 * X)
	  Formula2 = (X - D)
	  Do
		 'What do I put here to make my "Loop Until Work"

	  Loop Until Math.Abs(Formula1 / Formula2) < 0.0000001
	  Console.ReadLine()
	  Return X
   End Function 'SquareRoot
End Module



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: How do I get this to work? Please Help!

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How do I get this to work? Please Help!

Posted 17 August 2009 - 09:22 PM

First and foremost this is VB.NET code so I'm moving this to the VB.NET forum.

Second:

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: How do I get this to work? Please Help!

Posted 18 August 2009 - 07:48 AM

I assume that you are not to use result = Math.Sqrt(A)?

Second, your code cannot work as setup as D is uninitialized when you do Formula2 = (X - D)

Third, assuming you must implement an iterative root finder, what algorithm are you using? (I don't recognize that particular equation pair) See the wikipedia article on square root algorithms as it seems pretty comprehensive.
Was This Post Helpful? 0
  • +
  • -

#4 pgaroots  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-August 09

Re: How do I get this to work? Please Help!

Posted 18 August 2009 - 02:09 PM

View PostPsychoCoder, on 17 Aug, 2009 - 08:22 PM, said:

First and foremost this is VB.NET code so I'm moving this to the VB.NET forum.

Second:

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1