Tuesday, 27 August 2013

Method Returning Zero in C#

Method Returning Zero in C#

I'm a total rookie in C# and coming from a Java background in College. I'm
trying to write a simple calculator where a user inputs their weight and
bodyfat percentage and the program tells them their Lean Body Mass. When
debugging it always seems to say their lean body mass is the same as their
weight leading me to believe that the getBodyfatAmount is returning 0. I
just can't seem to find the problem. Any help would be VERY apppreciated
:):
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";
}
}
}
}

No comments:

Post a Comment