数学计算不起作用

本文关键字:不起作用 计算 | 更新日期: 2023-09-27 18:00:34

我有3个全局变量V1保存V2*V3,但它工作不正常
我在数学代码处进行了中断调试,V2和V3的值正确,但V1的值为0.0
有人能帮我吗。

某些代码:

costofAlligor = Alligor * AlligorInput;

这2行来自调试屏幕

Alligor 2781.9浮子
AlligorInput 500.0浮动

以及完整的数学代码块:

private void button1_Click(object sender, EventArgs e)
{
    costofAlligor = Alligor * AlligorInput;
    costofBriochit = Briochit * BriochitInput;
    costofChollonin = Chollonin * CholloninInput;
    costofEspitium = Espitium * EspitiumInput;
    costofHydrobenol = Hydrobenol * HydrobenolInput;
    costofIsopropenetol = Isopropenetol * IsopropenetolInput;
    costofMetachropin = Metachropin * MetachropinInput;
    costofPhlobotil = Phlobotil * PhlobotilInput;
    costofPlasteosine = Plasteosine * PlasteosineInput;
    costofPolynitrocol = Polynitrocol * PolynitrocolInput;
    costofPolynucleit = Polynucleit * PolynucleitInput;
    costofPrilumium = Prilumium * PrilumiumInput;
    costofStatchanol = Statchanol * StatchanolInput;
    costofTitanium = Titanium * TitaniumInput;
    costofVitricyl = Vitricyl * VitricylInput;
    totalCost = costofAlligor + costofBriochit 
        + costofChollonin + costofEspitium 
        + costofHydrobenol + costofIsopropenetol 
        + costofMetachropin + costofPhlobotil 
        + costofPlasteosine + costofPolynitrocol 
        + costofPolynucleit + costofPrilumium 
        + costofStatchanol + costofTitanium 
        + costofVitricyl;
}

form2的整个代码如下:http://pastebin.com/87q29tHp
我觉得链接会更好用,因为它很长
我知道很多数学可以做得更好或不同,但我正在学习编程,这是我目前唯一知道如何做的方法。

数学计算不起作用

示例。。。

class Sample1
{
    #region Private member variables ('costOf' and 'Input' data)
    float _Alligor;
    float _Briochit;
    float _Chollonin;
    // ... etc, etc.
    #endregion
    #region Public Properties for costOf and Input data
    public float Alligor { get { return _Alligor; } set { _Alligor = value; } }
    // ... etc. etc.
    #endregion
    public void Calculate()
    {
        costofAlligor = Alligor * AlligorInput;
        costofBriochit = Briochit * BriochitInput;
        costofChollonin = Chollonin * CholloninInput;
        costofEspitium = Espitium * EspitiumInput;
        costofHydrobenol = Hydrobenol * HydrobenolInput;
        costofIsopropenetol = Isopropenetol * IsopropenetolInput;
        costofMetachropin = Metachropin * MetachropinInput;
        costofPhlobotil = Phlobotil * PhlobotilInput;
        costofPlasteosine = Plasteosine * PlasteosineInput;
        costofPolynitrocol = Polynitrocol * PolynitrocolInput;
        costofPolynucleit = Polynucleit * PolynucleitInput;
        costofPrilumium = Prilumium * PrilumiumInput;
        costofStatchanol = Statchanol * StatchanolInput;
        costofTitanium = Titanium * TitaniumInput;
        costofVitricyl = Vitricyl * VitricylInput;
        totalCost = costofAlligor + costofBriochit + costofChollonin + costofEspitium + costofHydrobenol + costofIsopropenetol + costofMetachropin + costofPhlobotil + costofPlasteosine + costofPolynitrocol + costofPolynucleit + costofPrilumium + costofStatchanol + costofTitanium + costofVitricyl;
    }
    double totalCost;
    public double TotalCost { get { return totalCost;  } }
}

您可以使用断言检查代码,看看有什么问题。

using System.Diagnostics;
private void button1_Click(object sender, EventArgs e)
{
    Debug.Assert(Alligor > 0.0);
    Debug.Assert(AlligorInput > 0.0);
    costofAlligor = Alligor * AlligorInput;
    Debug.Assert(costofAlligor > 0.0);
    ...
}