CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2008
    Posts
    5

    computing slope, please help

    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();

    }
    }
    }

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: computing slope, please help

    You're almost there. Do it like you did the other
    Code:
    textBox7.Text = (int.Parse(textBox3.Text) / int.Parse(textBox6.Text)).ToString();
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Oct 2008
    Posts
    5

    Re: computing slope, please help

    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?

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: computing slope, please help

    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.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  5. #5
    Join Date
    Oct 2008
    Posts
    5

    Re: computing slope, please help

    ok i re did the porject, it works now. Thanks SMA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured