Jump to content
  • Sign up for free and receive a month's subscription

    You are viewing this page as a guest. That means you are either a member who has not logged in, or you have not yet registered with us. Signing up for an account only takes a minute and it means you will no longer see this annoying box! It will also allow you to get involved with our friendly(ish!) community and take part in the discussions on our forums. And because we're feeling generous, if you sign up for a free account we will give you a month's free trial access to our subscriber only content with no obligation to commit. Register an account and then send a private message to @dave u and he'll hook you up with a subscription.

Can anyone tell me why this C Sharp code doesn't work


Antynwa
 Share

Recommended Posts

    do
               if (newest > number1 + 0.00000005)
               {
                   newest = newest + number1 / newest / 2;
                   txtNew.Text = txtNew.Text + String.Format("\r\n The Next iteration is {0} more", newest);



               } while (newest > number1 + 0.00000005)

 

Basically the program is designed to repeat until it gets within +/- 0.00000005 of the square root of something.

 

Now if I predict the square root to be lower then it works perfectly (See code below), but if I predict higher my program just crashes.

 

Any ideas?

 

I.E

if (newest < number1 - 0.00000005)
               {
                   newest = newest + number1 / newest / 2;
                   txtNew.Text = txtNew.Text + String.Format("\r\n The next iteration is {0} less", newest);



               } while (newest < number1 - 0.00000005);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...