如何修正有关双打的数学方程式

时间:2019-04-27 19:50:19

标签: c#

我正在使用带有C#的视觉工作室,并且试图找出化学能方程。

要解析方程式,我尝试使用将变量设置为double,string和TextBox的方法。在计算按钮中,我尝试进行Convert.ToDouble解析,但是我仍然遇到相同的三个错误。它是Nan错误,格式异常或0。

#region variables
 // names for all variables
    string name;
    string material;
    string date;
    string time;
    TextBox joules; // maybe string or Text Box
    double kg;     // maybe string or Text Box  
    double msec;   // maybe string or Text Box msec.Text
    double totalJoules;
    double totalKg;
    double totalMsec;
    double totalP1Msec;

还有

private void calculateButton_Click(object sender, EventArgs e)
{
  // if kinetic energy clicked, use formula
  if (kineticEnergyCB.Checked == true ) // && double.TryParse(kineticEnergyCB.Text, out joules)

  {
  // If I recieve a format exception, then there is a problem in how the form is taking in the text
 totalJoules = Convert.ToDouble(kg) * 0.5 * Convert.ToDouble(msec) * Convert.ToDouble(msec);
   //  kineticEnergyTB = totalJoules;
   // kg.Text                 
    }
     else
     {
      // If mass clicked, use manipulated formula
      if (massCB.Checked == true ) // && double.TryParse(kineticEnergyCB.Text, out kg)
      {
       totalKg = 2 *Convert.ToDouble(joules.Text) / Convert.ToDouble(msec) * Convert.ToDouble(msec);
        //  massTB = totalkg;                 
       }
        else
        {
         // If velocity clicked, use manipulated formula
          if (velocityCB.Checked == true ) // && double.TryParse(kineticEnergyCB.Text, out msec)
         {
          totalP1Msec = 2 * Convert.ToDouble(joules) / Convert.ToDouble(kg);
           totalMsec = Math.Sqrt(totalP1Msec);
           // velocityTB = totalMsec;
          }
      }
 }

我期望该公式采用公斤,焦耳,毫秒并乘以 相应地划分。例如,如果我要计算焦耳, 公式为kg * 0.5 * msec * msec。公式应取 在文本框中显示一个数字,但我却收到0或Nan。

0 个答案:

没有答案