May 2008
Beginner
550 pages
13h 22m
English
The code has a user interface with two textboxes for getting the starting and ending heights for the table and a listbox or ListView object to present the results. The button click event code does most of the work and one solution using a listbox is shown here:
const double MININCHES = 36;
const double MAXINCHES = 96;
private void btnCalc_Click(object sender, EventArgs e)
{
bool flag;
int i;
int j;
double start;
double end;
double male;
double female;
double[,] idealWeights;
string buff;
//=================== Input ==========================
flag = double.TryParse(txtStart.Text, out start); // Table start
if (flag == false)
{
MessageBox.Show("Numeric only.");
txtStart.Focus();
return;
}
flag = double.TryParse(txtEnd.Text, out end); // Table end if (flag == false) { MessageBox.Show("Numeric only."); txtEnd.Focus(); return; } //=================== Validate Inputs ================ if (start < MININCHES || start > MAXINCHES) // Check table limits { MessageBox.Show("Table can only span " + MININCHES.ToString() + " to " + MAXINCHES + " inches."); txtStart.Focus(); return; } if (end < MININCHES || end > MAXINCHES) { MessageBox.Show("Table can only span " + MININCHES.ToString() + " to " + MAXINCHES + " inches."); txtStart.Focus(); return; } if (end <= start) // Can we display anything? { MessageBox.Show("Starting value must be less than ending value"); txtStart.Focus(); return; } // Define the array for table data idealWeights = new double[2, ...Read now
Unlock full access