我正在尝试用 C# 编写一个简单的计算器,用户输入他们的体重和体脂百分比,程序会告诉他们他们的瘦体重。在调试时,似乎总是说他们的瘦体重与他们的体重相同导致我相信 getBodyfatAmount 返回 0。
namespace Fitness_Calcualtors
{
public partial class Lean_Body_Mass : PhoneApplicationPage
{
int bodyWeight, bodyFatPercentage, leanBodyMass, bodyFatAmount;
public Lean_Body_Mass()
{
InitializeComponent();
}
private int getBodyfatAmount()
{
bodyFatAmount = ((bodyFatPercentage / 100) * bodyWeight);
return bodyFatAmount;
}
private void convertInput()
{
bodyWeight = Convert.ToInt32(bodyweightTextBox.Text);
bodyFatPercentage = Convert.ToInt32(bodyFatTextBox.Text);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (kilogramsRadioButton.IsChecked ==true)
{
convertInput();
getBodyfatAmount();
leanBodyMass = (bodyWeight - bodyFatAmount);
resultTextBox.Text = leanBodyMass.ToString() + " Kilos";
}
else if (poundsRadioButton.IsChecked == true)
{
convertInput();
getBodyfatAmount();
leanBodyMass = (bodyWeight - bodyFatAmount);
resultTextBox.Text = leanBodyMass.ToString() + " Lbs";
}
}
}
}