I am having some trouble completing this exercise and I would appreciate some input.
Currently I have this code:
Code:
private void btnCalculate_Click(object sender, EventArgs e)
{
double i;
bool flag;
double startingHeight;
double endHeight;
//Check for user input
if (txtStartingHeight.Text == "" || txtEndHeight.Text == "")
{
MessageBox.Show("Please enter starting and ending heights", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (ddlGender.SelectedItem == null)
{
MessageBox.Show("Please select a geneder", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//Validate users input
flag = double.TryParse(txtStartingHeight.Text, out startingHeight);
if (flag == false)
{
MessageBox.Show("Please enter only numbers", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtStartingHeight.Focus();
return;
}
flag = double.TryParse(txtEndHeight.Text, out endHeight);
if (flag == false)
{
MessageBox.Show("Please enter only numbers", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtEndHeight.Focus();
return;
}
//Process
double range = endHeight - startingHeight; //Get the length of the array
Array[] heights = new Array[(int)range];
if ((string)ddlGender.SelectedValue == "Male") //Check which calculation to perform
{
for (i = startingHeight; i < endHeight; i++) //This will iterate through each height of the loop
{
}
}
}
}
So I have done some validation for user input and I have several variables which should hold everything I need (for now at least, I also think I am performing some unnecessary steps but lets look past those for now).
The bit which I am getting stumped on is that I want to perform the calculation for the weight in the for loop and then I guess populate each result into an ArrayList (or similar)
But I can't quite get this to work.
So what I think I should be doing is something like
Code:
for (i = startingHeight; i < endHeight; i++) //This will iterate through each height of the loop
{
4.0 * i -128 //Can't get this working :-(
}
store result in an array which I can then loop through to display the results, I just can't seem to write the part that does the actual calculation I think I am having trouble with syntax for this and types.
And it is really bugging me, I think I might have a face palm to my forehead moment if someone can point out the answer or a page reference as to how I would do this..I would be very grateful.