自从我在输出中添加文本以来,它一直在向中添加数字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
提交
取消