Jar*_*rri -1 c# label textbox winforms
今天我开始使用Windows Forms在C#中使用Visual Studio 2017创建一个项目.程序应计算具有矩形底座的金字塔的体积并显示结果.
问题是,如果我单击应显示结果的按钮,结果为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;
}
Run Code Online (Sandbox Code Playgroud)
有人能告诉我为什么结果总是0?
| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |