in english measurement system,1 yard equal 3 feet and 1 foot equals 12 inches.us
ID: 441633 • Letter: I
Question
in english measurement system,1 yard equal 3 feet and 1 foot equals 12 inches.use this information to create an application that lets the user convert distances to and form inches,feet and yards.the user enters the distance to be converted into a textbox.a listbox allows the user to select the units being converted form,and another listbox allows the user to select the units being converted to. *be sure to handle the situation where the user picks the same units from both list boxes.the converted value will be the same as the value entered. note:i want the solution in c# not in c++ plzExplanation / Answer
Hi,
Below onclick event code gives you desired output.
private void btnConvert_Click(object sender, EventArgs e)
{
int distanceIn;
int distanceOut;
distanceIn = int.Parse(tbDistanceIn.Text);
string measureIn = listBox1.Items[listBox1.SelectedIndex].ToString();
string measureOut = listBox2.Items[listBox2.SelectedIndex].ToString();
switch(measureIn)
{
case 'Yard':
switch (measureOut)
{
case 'Yard':
distanceOut = distancein;
break;
case 'Feet':
distanceOut = distancein * 3;
break;
case 'Foot':
distanceOut = distancein * 3 * 12;
break
}
break;
case 'Feet':
switch (measureOut)
{
case 'Yard':
distanceOut = distancein / 3;
break;
case 'Feet':
distanceOut = distancein;
break;
case 'Foot':
distanceOut = distancein * 12;
break
}
break;
case 'Foot':
switch (measureOut)
{
case 'Yard':
distanceOut = distancein / (3 * 12);
break;
case 'Feet':
distanceOut = distancein / 12;
break;
case 'Foot':
distanceOut = distancein;
break
}
break;
}
tbDistanceOut.Text = distanceOut;
}
Thanks,
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.