математический расчет не работает? - PullRequest
0 голосов
/ 29 июня 2011

У меня есть 3 глобальные переменные, V1 сохраняет V2 * V3, но это не работает правильно.
Я отладил с перерывом в математическом коде, и V2 и V3 имеют правильное значение, но V1 имеет 0.0
.помогите мне в этом.

некоторый код:

costofAlligor = Alligor * AlligorInput;

эти 2 строки взяты из экрана отладки

Alligor 2781.9 float
AlligorInput 500.0 float

и полный блок математического кода:

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;
}

весь код формы 2 находится здесь: http://pastebin.com/87q29tHp
я думал, что ссылка будет работать лучше, поскольку она вполнедолго.
Я знаю, что много математики можно сделать лучше или по-другому, но я изучаю программирование, и это единственный способ, которым я знаю, как сделать это в данный момент.

Ответы [ 2 ]

0 голосов
/ 29 июня 2011

Вы можете проверить свой код с утверждениями, чтобы увидеть, что не так.

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);
    ...
}
0 голосов
/ 29 июня 2011

Образец ...

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;  } }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...