WhoCares357
2008-03-05 19:33:28
I was bored today, so I just made a simple calculator that takes in a, b, c and spits out the discriminant and the two outcomes.
program QuadCalc; //by WhoCares357
//http://www.poopnsuch.com
//Fill in these below following this guide:(ax)x^2+(bx)x+(cx)
const
ax = 1;
bx = 1;
cx = 1;
//End fill
//no touchy below
var
disc, temp, answ1, answ2: double;
FinalAnsw1, FinalAnsw2: string;
function PosOrNeg(discr: double): integer;
begin
if (discr < 0) then
Result := 0; //negative
if (discr = 0) then
Result := 1; //0
if (discr > 0) then
Result := 2; //positive
end;
procedure calculatePos(a, b, c, discr: double; OneAns: boolean);
begin
answ1 := ((-1*b) + sqrt(discr))/(2*a);
if (OneAns = true) then
answ2 := answ1;
if (OneAns = false) then
answ2 := ((-1*b) - sqrt(discr))/(2*a);
FinalAnsw1 := FloatToStr(answ1);
FinalAnsw2 := FloatToStr(answ2);
end;
procedure calculateNeg(a, b, c, discr: double);
begin
temp := (disc * -1);
FinalAnsw1 := '(' + FloatToStr(b*-1) + ' + ' + FloatToStr(sqrt(temp)) + 'i) / ' +
FloatToStr(a*2);
FinalAnsw2 := '(' + FloatToStr(b*-1) + ' - ' + FloatToStr(sqrt(temp)) + 'i) / ' +
FloatToStr(a*2);
end;
procedure calculate(a, b, c: double);
begin
disc := (b*b)-(4*a*c);
if (PosOrNeg(disc) = 1) then
begin
calculatePos(a, b, c, disc, true);
end else if (PosOrNeg(disc) = 2) then
begin
calculatePos(a, b, c, disc, false);
end else
calculateNeg(a, b, c, disc);
end;
begin
ClearDebug;
calculate(ax, bx, cx);
WriteLn('Thanks for using QuadCalc by WhoCares357.');
WriteLn('Here are your answers...');
WriteLn('');
WriteLn('Answer 1: ' + FinalAnsw1);
WriteLn('Answer 2: ' + FinalAnsw2);
WriteLn('Discriminant: ' + FloatToStr(disc));
WriteLn('');
WriteLn('Don''t forget to visit http://www.poopnsuch.com');
end.