Go Back   Novahq.net Forum > Computers > Web design and Programming
FAQ Community Calendar Today's Posts Search

Web design and Programming Discuss website creation and other programming topics.

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-01-2010, 03:17 PM
--BulletMagnet-- is offline --BulletMagnet--
--BulletMagnet--'s Avatar
DF2 Forever

Join Date: Jun 2005
Location: USA
Posts: 718

Send a message via MSN to --BulletMagnet--
C# Quadratic Formula Calculator (Beginner)

I got tired of doing this for my math homework all the time, and didn't find a suitable web calculator that I liked.

I consider myself no more than a novice, so this serves as both help and an opportunity for any programmers out there to offer constructive criticism. I often find that I've taken the least efficient route when I'm programming something, so feel free to tell me ways in which I could have simplified the program.

Main Function
Code:
double formula_main(double a, double b, double c, double negorpos)
        {
            double result;
            result = (-b + negorpos*(Math.Sqrt(Math.Pow(b, 2) - 4 * a * c))) / (2 * a);

            // Value To Be Returned
            return result;
        }
Calling the Function (add this to a button click event or similar event handler)
Code:
            // Declare Variables
            double a, b, c, res1, res2;

            // Execute 
            // Ensure That The Input Boxes Hold Text
            if (txtA.Text != "" & txtB.Text != "" & txtC.Text != "")
            {
                // Assign User Input To Variables
                // C# Cannot Accept The String Value Like C++, You Must Convert It
                // With the Parse method of the Integer class
                a = int.Parse(txtA.Text);
                b = int.Parse(txtB.Text);
                c = int.Parse(txtC.Text);

                // Perform Function
                res1 = formula_main(a, b, c, 1);
                res2 = formula_main(a, b, c, -1);

                // Display Results
                txtZeros.AppendText(res1.ToString());
                txtZeros.AppendText(Environment.NewLine + res2.ToString());
            }
NOTE: txtA, txtB, and txtC are the respective names of three TextBoxes I placed on the form to accept user input. txtZeros is a multiline TextBox which displays the results.

I haven't added many accessories yet, besides a simple copy button to copy the results. I'm working on some validation in the TextBox, and for now, imaginary numbers are not supported and all radicals must be simplified before inputting them.

Feel free to use.
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Atlantica Online Guides : Beginner Guide kaninigyy Gaming Talk 0 01-21-2010 02:55 AM
Perl beginner's guide .::nØ燎ƒµEL::. Web design and Programming 6 12-11-2005 07:26 AM
grade calculator BOne Web design and Programming 2 12-10-2004 02:54 PM
Sigs For Beginner tennis_rocks Sigs and Graphics 15 07-23-2004 12:41 PM
beginner stuff katana*GFR* Sigs and Graphics 5 11-15-2003 07:29 PM


All times are GMT -5. The time now is 09:45 AM.




Powered by vBulletin®