Guest User

Untitled

a guest
Oct 19th, 2019
991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3.  
  4. namespace DistanceConverter
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.  
  13.         private void buttonConvert_Click(object sender, EventArgs e)
  14.         {
  15.             double userInput = Convert.ToDouble(textBoxEnterDistance.Text);
  16.  
  17.             double temp;
  18.  
  19.             double sr = userInput / 2;
  20.  
  21.             if (userInput > 0 || //not a text or empty)
  22.             {
  23.                 do
  24.                 {
  25.                     temp = sr;
  26.                     sr = (temp + (userInput / temp)) / 2;
  27.                 } while ((temp - sr) != 0);
  28.  
  29.                 textBoxConvertedDistance.Text = sr.ToString();
  30.                
  31.  
  32.             }
  33.             else
  34.             {
  35.                 MessageBox.Show("You must use digits and your number must be positive");
  36.             }
  37.  
  38.  
  39.            
  40.            
  41.         }
  42.  
  43.  
  44.         private void buttonExit_Click(object sender, EventArgs e)
  45.         {
  46.             Application.Exit();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment