none
Need some help coding the next step.

    Question



  • Okay so here is what I am suppose to be coding I have the calculator all set up except the part that actually makes it work.

    Here is the code so far. I have for the calculator.

     public partial class Form1 : Form
        {
            //Declarations
            decimal Length;
            decimal Width;
            //
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                Length = Convert.ToDecimal(LengthBox.Text);
               
                Width = Convert.ToDecimal(WidthBox.Text);

                decimal Area = Width * Length;

                decimal Perimeter = 2 * Width + 2 * Length;

    Now basically how do I get it to work I know that I am suppose to write a string, but i'm not 100% sure where to start but ya thats what I have so far if anyone can help out I have all the calculator built just need it to do the calculation.

     

    Well I tried adding a picture of what it looks like but apparently not, anyways lets say there is a Length:[                 ]   < is a text box

    Width: [               ] < text box

    Area: [                  ] < label then i just took the text out then used borderstyle 3d

    Perimeter [             ]  < Label then the same thing as the area.

    basically the user is suppose to input two numbers into the length and width and the results are meant to show in the area and perimeter.





    • Edited by Lalor21 Wednesday, September 28, 2011 11:42 PM
    Wednesday, September 28, 2011 11:28 PM

Answers

  •  

            private void button1_Click(object sender, EventArgs e)
             {
                 decimal Length = Convert.ToDecimal(LengthBox.Text);
                 
                decimal Width = Convert.ToDecimal(WidthBox.Text);
     
                decimal Area = Width * Length;
     
                decimal Perimeter = 2 * Width + 2 * Length;
    
                TxtArea.Text = Area.ToString();  //display the result of area in a textbox
                TxtPerimeter.Text = Perimeter.ToString() //Idem Dito for perimeter
    
          }
    

    Now, you did make the calculations, in variables, but you forgot to assign them to a textbox.

     

    So change your code to the above.

    Regards,

    Dylan Meeus


    0x2B |~ 0x2B Blog : www.it-ca.net/blogdylan
    • Edited by Dylan-Meeus Wednesday, September 28, 2011 11:44 PM forgot something
    • Proposed as answer by Dylan-Meeus Wednesday, September 28, 2011 11:48 PM
    • Marked as answer by Martin_XieModerator Thursday, September 29, 2011 5:27 AM
    Wednesday, September 28, 2011 11:43 PM
  • Now now, it's not dumb, small mistakes are quite common, you'd have found it if you looked over it step per step :)

    If it's solved, please mark as answered.

    Regards,

    Dylan Meeus


    0x2B |~ 0x2B Blog : www.it-ca.net/blogdylan
    • Marked as answer by Lalor21 Wednesday, September 28, 2011 11:55 PM
    Wednesday, September 28, 2011 11:48 PM

All replies

  •  

            private void button1_Click(object sender, EventArgs e)
             {
                 decimal Length = Convert.ToDecimal(LengthBox.Text);
                 
                decimal Width = Convert.ToDecimal(WidthBox.Text);
     
                decimal Area = Width * Length;
     
                decimal Perimeter = 2 * Width + 2 * Length;
    
                TxtArea.Text = Area.ToString();  //display the result of area in a textbox
                TxtPerimeter.Text = Perimeter.ToString() //Idem Dito for perimeter
    
          }
    

    Now, you did make the calculations, in variables, but you forgot to assign them to a textbox.

     

    So change your code to the above.

    Regards,

    Dylan Meeus


    0x2B |~ 0x2B Blog : www.it-ca.net/blogdylan
    • Edited by Dylan-Meeus Wednesday, September 28, 2011 11:44 PM forgot something
    • Proposed as answer by Dylan-Meeus Wednesday, September 28, 2011 11:48 PM
    • Marked as answer by Martin_XieModerator Thursday, September 29, 2011 5:27 AM
    Wednesday, September 28, 2011 11:43 PM
  • Wow i'm dumb thanks a lot!
    Wednesday, September 28, 2011 11:46 PM
  • Now now, it's not dumb, small mistakes are quite common, you'd have found it if you looked over it step per step :)

    If it's solved, please mark as answered.

    Regards,

    Dylan Meeus


    0x2B |~ 0x2B Blog : www.it-ca.net/blogdylan
    • Marked as answer by Lalor21 Wednesday, September 28, 2011 11:55 PM
    Wednesday, September 28, 2011 11:48 PM