【发布时间】:2018-11-30 15:40:45
【问题描述】:
今天我开始在 Visual Studio 2017 中使用 C# 和 Windows 窗体创建一个项目。该程序应计算具有矩形底面的金字塔的体积并显示结果。
问题是,如果我单击应该显示结果的按钮,结果为 0。
这是重要的代码:
// stores height h, side1 a, side2 b
double a, b, h;
//Reads out b from a textbox
private void txbB_TextChanged(object sender, EventArgs e)
{
string parseB = txbB.Text;
b = double.Parse(parseB);
}
//Reads out a from a textbox
private void txbA_TextChanged(object sender, EventArgs e)
{
string parseA = txbA.Text;
a = double.Parse(parseA);
}
//Reads out h from a textbox
private void txbH_TextChanged(object sender, EventArgs e)
{
string parseH = txbH.Text;
h = double.Parse(parseH);
}
//button which calculates the volume of the pyramid
//when clicked and prints it to the label "LblErgebnis"
private void Cmdrechnen_Click(object sender, EventArgs e)
{
double Total = 1/3 * h * a * b;
string Result = Total.ToString();
LblErgebnis.Text = Result;
}
谁能告诉我为什么结果总是0?
【问题讨论】:
-
@BradleyDotNET 自从几个月前我获得金牌后,我就已经有了,所以我不知道