2

I am trying to make a scroll bar that will convert the input from Celsius into Fahrenheit. I am having trouble with the maths for the conversion:

private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
    decimal x = 1.8m;
    int y = 32;
    int z = vScrollBar1.Value;
    label2.Text = (z. * x + y);
    label1.Text = vScrollBar1.Value.ToString();
}
rbm
  • 3,243
  • 2
  • 17
  • 28
jayjay1487
  • 38
  • 3

1 Answers1

4

Compute the value

 C = (F - 32) / 9 * 5

and then represent it with the desired format:

private void vScrollBar1_Scroll(object sender, ScrollEventArgs e) {
  var F = vScrollBar1.Value;   
  var C = (F - 32.0) / 9.0 * 5.0;

  label1.Text = F.ToString();
  // "F1" - let have 1 digit after the decimal point
  label2.Text = C.ToString("F1"); 
}
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215