Click to See Complete Forum and Search --> : computing slope, please help


xodus8
October 19th, 2008, 12:28 PM
Hello, I am doing an assignment, I need to get a program that figures out slope. I am almost done, I am having writing the last part. I need to divide the numerator by the denominator. I have copied the code below. Thanks


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int y1, y2, numerator;
int x1, x2, denominator;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
y2 = int.Parse(textBox1.Text);
y1 = int.Parse(textBox2.Text);
numerator = y2 - y1;
textBox3.Text = numerator.ToString();


}

private void button2_Click(object sender, EventArgs e)
{
x2 = int.Parse(textBox4.Text);
x1 = int.Parse(textBox5.Text);
denominator = x2 - x1;
textBox6.Text = denominator.ToString();
}

private void button3_Click(object sender, EventArgs e)
{
textBox7.Text = textBox3.Text / textBox6.Text.ToString();

}
}
}

S_M_A
October 19th, 2008, 01:02 PM
You're almost there. Do it like you did the othertextBox7.Text = (int.Parse(textBox3.Text) / int.Parse(textBox6.Text)).ToString();

xodus8
October 19th, 2008, 01:34 PM
ok, i run the program, but for some reason it isnt giving me the correct values of x2 - x1. I looked at the code everything looks right. The division works right, y2-y1 gives the right value, but for some odd reason x2-x1 doesnt give the right answer. What can i do to fix this?

S_M_A
October 19th, 2008, 01:46 PM
Are you referring to the proper text boxes? Set a breakpoint and run it in the debugger and check that you get the values you expect to get.

Also, I just realized that I rushed my last answer a bit to much. You probably want to use double for the slope calculation.

xodus8
October 19th, 2008, 01:52 PM
ok i re did the porject, it works now. Thanks SMA