Quadratic Formula Solver

  • Uploaded by: Frank
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Quadratic Formula Solver as PDF for free.

More details

  • Words: 327
  • Pages: 2
#!/usr/bin/perl system("clear"); print "QUADRATIC FORMULA SOLVER\n"; print "The program will be unable to solve imaginary numbers and letter inputs.\n\n"; print "a/ > "; chomp($a = <>); print "b/ > "; chomp($b = <>); print "c/ > "; chomp($c = <>); my $plus_answer = sprintf "%.5f\n",(-($b) + sqrt(($b**2) - (4*$a*$c)))/(2*$a); my $negative_answer = sprintf "%.5f\n",(-($b) - sqrt(($b**2) - (4*$a*$c)))/(2*$a); print "\nx1 = $plus_answer\n"; print "x2 = $negative_answer\n\n"; &ask_question; sub ask_question { print "Do you want to know how to do it? (y/n/h) > "; chomp($d = <>); if($d eq "y") { &how_to; } elsif($d eq "n") { exit; } elsif($d eq "h") { &help_screen; }else{ print "\"$d\" is invalid. Choose between 'y' or 'n'.\n\n"; &ask_question;

} }

sub help_screen { use Term::ANSIColor; print color 'bold blue'; print "The first step of the program will only show you the answer up to 5 decimals.\n"; print "For more decimals, you will have to type 'y' at the above question.\n"; print color 'reset'; &ask_question; } sub how_to { use Term::ANSIColor; system("clear"); print "How to do it...\n\n"; print color 'bold blue'; print "Formula: (-(b) ± squareroot[(b^2) - (4ac)])/(2a)\n\n"; print color 'reset';

print color 'bold blue'; print "a = $a\n"; print "b = $b\n"; print "c = $c\n\n"; print color 'reset'; my my my my my my my my

$fourac = 4*$a*$c; $twoa = 2*$a; $bptwo = $b**2; $sqrttotal = sqrt($bptwo - $fourac); $firstbracket_x1 = (-($b) + $sqrttotal); $firstbracket_x2 = (-($b) - $sqrttotal); $final_ans_x1 = $firstbracket_x1 / $twoa; $final_ans_x2 = $firstbracket_x2 / $twoa;

print "x1 print "x1 print "x1 print "x1 print color print "x1 print color

= (-($b) + sqrt(($b^2) - (4*$a*$c)))/(2*$a)\n"; = (-($b) + sqrt($bptwo - $fourac))/($twoa)\n"; = (-($b) + $sqrttotal)/$twoa)\n"; = $firstbracket_x1 / $twoa\n"; 'bold blue'; = $final_ans_x1\n\n"; 'reset';

print "x2 print "x2 print "x2 print "x2 print color print "x2 print color exit; }

= (-($b) - sqrt(($b^2) - (4*$a*$c)))/(2*$a)\n"; = (-($b) - sqrt($bptwo - $fourac))/($twoa)\n"; = (-($b) - $sqrttotal)/$twoa)\n"; = $firstbracket_x2 / $twoa\n"; 'bold blue'; = $final_ans_x2\n\n"; 'reset';

Related Documents


More Documents from ""

Ct-g2175 Panasonic Diagrama
December 2019 36
May 2020 12
Irc Bot V.2.1
June 2020 15
980908_02rev
May 2020 12
Irc Bot V.2.0
May 2020 16