Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- namespace DistanceConverter
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void buttonConvert_Click(object sender, EventArgs e)
- {
- double userInput = Convert.ToDouble(textBoxEnterDistance.Text);
- double temp;
- double sr = userInput / 2;
- if (userInput > 0 || //not a text or empty)
- {
- do
- {
- temp = sr;
- sr = (temp + (userInput / temp)) / 2;
- } while ((temp - sr) != 0);
- textBoxConvertedDistance.Text = sr.ToString();
- }
- else
- {
- MessageBox.Show("You must use digits and your number must be positive");
- }
- }
- private void buttonExit_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment