我有3个全局变量V1保存V2 * V3,但它无法正常工作
我在数学代码处休息调试,V2和V3具有正确的值,但V1具有0.0
任何人都可以帮助我。
一些代码:
costofAlligor = Alligor * AlligorInput;
这两行来自调试屏幕
Alligor 2781.9浮动
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;
}
form2的整个代码在这里:http://pastebin.com/87q29tHp
我认为链接会更好,因为它很长
我知道很多数学可以做得更好或不同但我正在学习编程,这是我知道如何做到这一点的唯一方法。
答案 0 :(得分:0)
示例......
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; } }
}
答案 1 :(得分:0)
您可以使用断言检查代码以查看错误。
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);
...
}