为了账号安全,请及时绑定邮箱和手机立即绑定

输出行将数字添加到用户输入上(Windows窗体)

输出行将数字添加到用户输入上(Windows窗体)

C#
www说 2021-04-07 14:15:41
自从我在输出中添加文本以来,它一直在向中添加数字inputTemperature。例如,如果用户输入“ 10 ”,则输出行将显示:“ -112摄氏度转换为...”,并且转换将是正确的。您对导致这种情况的发生有任何想法吗?// VARIABLESdouble inputTemperature;  // Stores user inputdouble celsius;  // Celsius valuedouble fahrenheit;  // Farhenheit value// INPUTif (double.TryParse(txtTemperature.Text, out inputTemperature) == false)  // Checking that user input is valid{    MessageBox.Show("ERROR: Please enter a numeric temperature to convert.");  // Error message that is displayed    txtTemperature.ResetText();  // Resets the form    txtTemperature.Focus();  // Places the user's cursor back in the Temperature textbox}// PROCESSINGif (optCelsius.Checked)  // If the celsius button is clicked, then the temperature needs to be converted from fahrenheit{    fahrenheit = double.Parse(txtTemperature.Text);    fahrenheit = ((fahrenheit - 32) * 5 / 9);    lblNewTemperature.Text = fahrenheit.ToString(inputTemperature + " degrees Celsius converts to " + fahrenheit + " degrees Fahrenheit.");}else if (optFahrenheit.Checked)  // If the fahrenheit button is clicked, then the temperature needs to be converted from celsius{    celsius = double.Parse(txtTemperature.Text);    celsius = ((celsius * 9) / 5 + 32);    lblNewTemperature.Text = celsius.ToString(inputTemperature + " degrees Fahrenheit converts to " + celsius + " degrees Celsius.");}
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 122 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信