I need help creating a form that accepts a conversion type and that value to be converted from the user and then calculates the converted value.

The user selects the conversion to be performed from the combo box list and the application modifies the labels that indicate the "from" and "to" lengths accordingly. It also clears the "from" entry and the result of that last calculation.

The user enters the "from" length and clicks the Calculate button presses the Enter Key.

The program performs the conversion and displays the result.

To end the program the user clicks the Exit button or presses the Escape Key.

The application should check the length entered by the user to make sure it is a valid decimal value.

Mile to Kilometers 1 mile = 1.6093 kilometers
kilometers to miles 1 kilometer = 0.6214 miles
feet to meters 1 foot = 0.3048 meters
meters to feet 1 meter = 3.2808 feet
inches to centimeters 1 inch = 2.54 centimeters
centimeters to inches 1 centimeter = 0.3937 inches

Hi BCJLJ and welcome to DaniWeb :)

So what have you got so far, and where are you having trouble? Unfortunately we can't help you without some showing of effort on your part. Have a try yourself, or at least try to write some sort of algorithm, and then re-post with your ideas and raise some specific questions.

Good luck,
darkagn

namespace Conversions
{
    public partial class frmConversions : Form
    {
        const double Miles_PER_Kilometers = 1.6093;
        const double Kilometers_PER_Miles = 0.6214;
        const double Feet_PER_Meters = 0.3048;
        const double Meters_PER_Feet = 3.2808;
        const double Inches_PER_Centimeters = 2.54;
        const double Centimeters_PER_Inches = 0.3937;

        public frmConversions()
        {
            InitializeComponent();
        }

        string[,] convert = { {"Miles to Kilometers", "1.6093"},
                       {"Kilometers to Miles", "0.6214"},
                       {"Feet to Meters", "0.3048"},
                       {"Meters to Feet", "3.2808"},
                       {"Inches to Centimeters", "2.54"},
                       {"Centimeters to Inches", "0.3937"}}; 

        private void frmConversions_Load(object sender, EventArgs e)
        {
            cboNames.Items.Clear();
            for (int i = 0; i < convert.Length; i++)
            {
                cboNames.Items.Add(convert[i,0]);
            }            
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            int index = cboNames.SelectedIndex;
            if (index != -1)
            {
                label4.Text = "Miles";
                label3.Text = "Kilometers";
                double choice = Int32.Parse(cboNames.Items[index].ToString());
                double result = choice * 5;
                textBox2.Text = result.ToString();
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

Most of my problem is working with Arrays...Arrays confuse me. This program is supposed to made with a rectangular array.

Edited 3 Years Ago by Nick Evan: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.