CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Mar 2012
    Posts
    5

    Help squaring a variable

    I want to square a variable. Please help me.Here is my code:

    code:

    decimal number1 = Convert.ToInt32(textBox1.Text);
    double pi = Math.PI;
    double Radius_to_Circumference = (double)number1 * 2 * pi;
    double RTD = (double)number1 * 2;
    double RTA = (double)Math.Pow(number1, 2) * pi;
    MessageBox.Show("The circumference is " + Radius_to_Circumference + " \nThe Diameter is " + RTD + " \nThe Area is " +;

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Help squaring a variable

    Once again, you have not explained what the problem is. We are not your debuggers. Take some time and explain exactly what is going wrong instead of throwing some code at us and saying "make it work".
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

  3. #3
    Join Date
    Mar 2012
    Posts
    5

    Re: Help squaring a variable

    The program is made to tell you all the info of a circle by only putting in the area,radius,circumference or diameter
    The problem is here:
    double RTA = (double)Math.Pow(number1, 2) * pi;

    I wrote this afterwad and it worked:
    private void button2_Click(object sender, EventArgs e)
    {
    decimal number = Convert.ToInt32(textBox2.Text);
    double pi = Math.PI;
    double DTR = (double)number / 2;
    double DTC = (double)number * pi;
    double DTR2 =(double) number / 2;
    This is the part: double DTA = (double)Math.Pow(DTR2, 2) * pi;
    Last edited by yoda493; March 15th, 2012 at 04:45 PM.

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Help squaring a variable

    Math.Pow already returns a double, the cast is redundant.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

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