Go Back   Novahq.net Forum > Computers > Web design and Programming

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 08-19-2010, 07:19 PM
VooDoo- is offline VooDoo-
VooDoo-'s Avatar
Registered User

Join Date: Jan 2004
Location: Florida
Posts: 2,896

i did this on my ti92 .. not the exact code but similar ..

great time saver lol
__________________
Reply With Quote
  #3  
Old 08-21-2010, 09:26 AM
--BulletMagnet-- is offline --BulletMagnet--
--BulletMagnet--'s Avatar
DF2 Forever

Join Date: Jun 2005
Location: USA
Posts: 718

Send a message via MSN to --BulletMagnet--
True, it is an awesome time saver. I'm still having trouble with C# displaying imaginary numbers... that's the huge downside to the program now.
Reply With Quote
  #4  
Old 08-21-2010, 01:53 PM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
Looks good.
__________________
Reply With Quote
  #5  
Old 08-23-2010, 09:27 AM
VooDoo- is offline VooDoo-
VooDoo-'s Avatar
Registered User

Join Date: Jan 2004
Location: Florida
Posts: 2,896

well if you get an imaginary number as a result ... why do you care what it is? lol
__________________
Reply With Quote
  #6  
Old 08-23-2010, 11:23 AM
atholon is offline atholon
"ath-hole"

Join Date: Jan 2003
Location: Failville.
Posts: 11,357

Send a message via MSN to atholon
I think you also need to be handling exceptions that Int32.Parse throws.
__________________
Reply With Quote
  #7  
Old 08-23-2010, 07:46 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--
Quote:
Originally Posted by atholon View Post
i think you also need to be handling exceptions that int32.parse throws.
Quote:
Originally Posted by --bulletmagnet--
i'm working on some validation in the textbox...
Reply With Quote
  #8  
Old 08-26-2010, 11:58 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--
Quote:
Originally Posted by VooDoo- View Post
well if you get an imaginary number as a result ... why do you care what it is? lol
Because the professor cares... lol.
Reply With Quote
  #9  
Old 09-04-2010, 12:39 AM
VooDoo- is offline VooDoo-
VooDoo-'s Avatar
Registered User

Join Date: Jan 2004
Location: Florida
Posts: 2,896

then i don't even want to know what the hell kind of math you do lol
__________________
Reply With Quote
  #10  
Old 09-10-2010, 09:41 AM
ShadowZ is offline ShadowZ
Chick Magnet(?)

Join Date: Jun 2009
Location: The "Mud Hole," USA
Posts: 295

Quote:
Originally Posted by --BulletMagnet-- View Post
True, it is an awesome time saver. I'm still having trouble with C# displaying imaginary numbers... that's the huge downside to the program now.
If it is not in the math library, then you might have to program a short section of code that says "sqrt(-1) = j"
__________________
True forgiveness comes not from those who pull the trigger, but from those who have
Reply With Quote
  #11  
Old 09-13-2010, 12:11 AM
--BulletMagnet-- is offline --BulletMagnet--
--BulletMagnet--'s Avatar
DF2 Forever

Join Date: Jun 2005
Location: USA
Posts: 718

Send a message via MSN to --BulletMagnet--
Quote:
Originally Posted by ShadowZ View Post
If it is not in the math library, then you might have to program a short section of code that says "sqrt(-1) = j"
Yea that might be a necessity. Are you a programmer yourself?
Reply With Quote
  #12  
Old 09-13-2010, 11:19 PM
ShadowZ is offline ShadowZ
Chick Magnet(?)

Join Date: Jun 2009
Location: The "Mud Hole," USA
Posts: 295

Quote:
Originally Posted by --BulletMagnet-- View Post
Yea that might be a necessity. Are you a programmer yourself?
A little bit. I major in EEEN but I do have some basic C++ knowledge.

Most of the coding I do nowadays is either modding the .def files for DFx2 or assembly language for the HCS9S12.

Also got a bit of experiance with the Ti-83
__________________
True forgiveness comes not from those who pull the trigger, but from those who have
Reply With Quote
Reply


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

Advanced Search
Display Modes

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 07:12 AM.




Powered by vBulletin®