Results 1 to 9 of 9

Thread: Quadratic Formula for SCAR

  1. #1
    Join Date
    Feb 2006
    Location
    Wisconsin (like farm-town, USA) :P
    Posts
    254
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Quadratic Formula for SCAR

    Whiteshadow wanted help for his homework, this is the result I'm giving him It shows most of the work that goes into it, so it's nice and easy. It has two variables you can get answers from (since two answers usually come out of this). It also shows if there are no solutions. It returns true if there is a solution, and false if there is not. I enjoyed making this one
    Code:
    function QuadraticFormula(a,b,c: extended; var answer1,answer2: extended): boolean;
    var i: extended;
    begin
      Writeln('('+FloatToStr(b*-1)+' ± SquareRoot('+FloatToStr(Sqr(b))+' - 4('+FloatToStr(a)+')('+FloatToStr(c)+'))) / '+FloatToStr(a*2));
      i := Sqr(b)-(4*a*c);
      If(i<0)Then
        begin
          Result := false;
          answer1 := 0;
          answer2 := 0;
          Writeln('('+FloatToStr(b*-1)+' ± SquareRoot('+FloatToStr(i)+')) / '+FloatToStr(a*2)+' - No solutions');
          Exit;
        end;
      i := Sqrt(i);
      Writeln('('+FloatToStr(b*-1)+' ± '+FloatToStr(i)+') / '+FloatToStr(a*2));
      answer1 := ((b*-1) + i)/(a*2);
      answer2 := ((b*-1) - i)/(a*2);
      Result := true;
    end;
    Maybe someone else will like this or thank me for it

  2. #2
    Join Date
    Feb 2006
    Location
    L.A, USA
    Posts
    1,632
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    W00t, thanks for listening to my request Driger. Now I can do my hmk in like fucking secs.
    Saved me an hour trying to make my own.
    ~WhiteShadow

  3. #3
    Join Date
    Feb 2006
    Location
    California-Foster City
    Posts
    742
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    You dont know how to to that really fast and u beat me in the SAT math!?

    jk nice script driger
    The Welcoming Party
    Don't be a Fakawi! Get 25 hours of sleep a day!

  4. #4
    Join Date
    Feb 2006
    Location
    L.A, USA
    Posts
    1,632
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Sdcit
    You dont know how to to that really fast and u beat me in the SAT math!?

    jk nice script driger
    I'm smarter than j00.

    I'm kidding..haha

    Code:
    procedure QuadraticSolver(a, b, c : Integer);
    var
      z, g, A1, A2 : Extended;
    begin
      Writeln('<---------------------------------------------------------->');
      Writeln('Showing Work Too');
      Writeln('1st Line : '+FloatToStr(-1 * b)+' ± SquareRoot('+FloatToStr(Sqr(b))+ '-4('+FloatToStr(a)+')('+FloatToStr(c)+'))) / '+FloatToStr(a*2));
      z:= Sqr(b)-(4* a *c);
      Writeln('2nd Line : '+FloatToStr(b*-1)+' ± SquareRoot('+FloatToStr(z)+') / '+FloatToStr(a*2));
      z:= Sqrt(z);
      g:= (-1 * b)
      A1:=(g + z) / 2;
      A2:=(g - z) / 2;
      Writeln('+ Answer : '+FloatToStr(A1))
      Writeln('- Answer : '+FloatToStr(A2))
      Writeln('<---------------------------------------------------------->');
    end;
    Example of how to use:

    Code:
    begin
      QuadraticSolver(5, -11, 2);
    end.

    I made one too, how is it driger?

  5. #5
    Join Date
    Feb 2006
    Location
    Wisconsin (like farm-town, USA) :P
    Posts
    254
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It won't work.

    Test it using a=1 b=2 c=3

  6. #6
    Join Date
    Feb 2006
    Location
    L.A, USA
    Posts
    1,632
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ok, Mr. NoRunTimes... ;p

    I edited.

    Code:
    procedure QuadraticSolver(a, b, c : Integer);
    var
      z, g, A1, A2 : Extended;
    begin
      Writeln('<---------------------------------------------------------->');
      Writeln('Showing Work Too');
      Writeln('1st Line : '+FloatToStr(-1 * b)+' ± SquareRoot('+FloatToStr(Sqr(b))+ '-4('+FloatToStr(a)+')('+FloatToStr(c)+'))) / '+FloatToStr(a*2));
      z:= Sqr(b)-(4* a *c);
      Writeln('2nd Line : '+FloatToStr(b*-1)+' ± SquareRoot('+FloatToStr(z)+') / '+FloatToStr(a*2));
      if(z > 0)then
      begin
        z:= Sqrt(z);
        g:= (-1 * b)
        A1:=(g + z) / 2;
        A2:=(g - z) / 2;
        Writeln('+ Answer : '+FloatToStr(A1))
        Writeln('- Answer : '+FloatToStr(A2))
        Writeln('<---------------------------------------------------------->');
      end else
      begin
        Writeln('Answer : No Solution(Can''t get the square root of a -number)');
      end;
    end;
    
    begin
      QuadraticSolver(1, 2, 3);
    end.

  7. #7
    Join Date
    Feb 2006
    Location
    Wisconsin (like farm-town, USA) :P
    Posts
    254
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Much better However, your work isn't ever brought outside of the procedure. I guess for your purpose that's fine though Good job WhiteShadow

  8. #8
    Join Date
    Feb 2006
    Location
    L.A, USA
    Posts
    1,632
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by driger1592
    Much better However, your work isn't ever brought outside of the procedure. I guess for your purpose that's fine though Good job WhiteShadow
    I can make the vars Global in 2 seconds. ;p

    Thanks, Driger.

  9. #9
    Join Date
    Feb 2006
    Location
    Wisconsin (like farm-town, USA) :P
    Posts
    254
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You're welcome You've always been quite a decent scripter

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Src] Simple quadratic equation solver
    By Freddy1990 in forum Java Help and Tutorials
    Replies: 7
    Last Post: 06-24-2007, 06:53 PM

Posting Permissions

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