Created
September 8, 2016 11:42
-
-
Save connrs/3f63d8f66dc9583557aff0d96aa2d0fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program trTriangle; | |
uses crt; | |
type triangle = record | |
len : Array[0..2] of Real; | |
Scal,Isos,Equi,Obtu,RAng,Refl : Boolean; | |
end; | |
var | |
inTri : triangle; | |
doneyet : Char; | |
loop : boolean; | |
{Math Functions - Removed} | |
{Input Functions} | |
procedure inputReal(var int1 : Real; var int2 : Real; var int3 : Real); | |
var | |
inpt,inpt1,inpt2,inpt3 : String; {The string input values} | |
err1,err2,err3,err4,errfree : Integer; {An error variable used to determine whether the three values inputted were correct} | |
rptd : Boolean; | |
loop : Integer; | |
f_count : Integer; | |
f_str : String; | |
begin | |
rptd := False; | |
repeat | |
f_count := 0; | |
err1:=0; | |
err2:=0; | |
err3:=0; | |
err4:=0; | |
inpt:=''; | |
inpt1 := ''; | |
inpt2 := ''; | |
inpt3 := ''; | |
textcolor(red); | |
if (rptd = True) then writeln('error, try again'); | |
textcolor(white); | |
readln(inpt); | |
f_str := inpt; | |
for loop := 1 to Length(f_str) do {This section splits the inputted string and places their values into inpt1-3} | |
begin | |
case (f_count) of | |
0: | |
begin | |
if f_str[loop]<>' ' then | |
inpt1 := inpt1 + f_str[loop] | |
else if (f_str[loop]=' ') AND (inpt1<>'') then f_count := 1; | |
end; | |
1: | |
begin | |
if f_str[loop]<>' ' then | |
inpt2 := inpt2 + f_str[loop] | |
else if (f_str[loop]=' ') AND (inpt2<>'') then | |
f_count := 2; | |
end; | |
2: | |
begin | |
if f_str[loop]<>' ' then | |
inpt3 := inpt3 + f_str[loop] | |
else if (f_str[loop]=' ') AND (inpt3<>'') then | |
f_count := 3; | |
end; | |
3: | |
begin | |
if f_str[loop]<>' ' then err4 := 1; | |
end; | |
end;{End case statement} | |
end; | |
val(inpt1,int1,err1); | |
val(inpt2,int2,err2); | |
val(inpt3,int3,err3); | |
rptd:=True; | |
errfree:=err1 or err2 or err3 or err4; | |
until(errfree = 0) | |
end; | |
procedure TriType(var tri : triangle); | |
var | |
obtuse1, obtuse2, obtuse3 : boolean; | |
rang1, rang2, rang3 : boolean; | |
acute1, acute2, acute3 : boolean; | |
begin | |
{Check what length type} | |
{Based on lengths, a triangle can be only Equilateral, Isosceles or Scalene} | |
{This if statement determines which and sets the appropriate value} | |
if ((tri.len[0]=tri.len[1]) and (tri.len[0]=tri.len[2]) and (tri.len[1]=tri.len[2])) then | |
begin | |
tri.Scal := False; | |
tri.Equi := True; {All sides are considered equal so the equilateral value is set as true} | |
tri.Isos := False; | |
end | |
else if ((tri.len[0]=tri.len[1]) or (tri.len[0]=tri.len[2]) or (tri.len[1]=tri.len[2])) then | |
begin | |
tri.Scal := False; | |
tri.Equi := False; | |
tri.Isos := True; {Only two sides are equal so the isosceles value is set as true} | |
end | |
else | |
begin | |
tri.Scal := True; {No sides are equal so the scalene value is set as true} | |
tri.Equi := False; | |
tri.Isos := False; | |
end; | |
{Check Angles} | |
{A triangle has three angles which can be of varying types} | |
{A triangle can be acute} | |
obtuse1 := (tri.len[0]>sqrt(sqr(tri.len[1])+sqr(tri.len[2]))); | |
obtuse2 := (tri.len[1]>sqrt(sqr(tri.len[0])+sqr(tri.len[2]))); | |
obtuse3 := (tri.len[2]>sqrt(sqr(tri.len[1])+sqr(tri.len[0]))); | |
tri.Obtu := (obtuse1 or obtuse2 or obtuse3); | |
rang1 := (tri.len[0]=sqrt(sqr(tri.len[1])+sqr(tri.len[2]))); | |
rang2 := (tri.len[1]=sqrt(sqr(tri.len[0])+sqr(tri.len[2]))); | |
rang3 := (tri.len[2]=sqrt(sqr(tri.len[1])+sqr(tri.len[0]))); | |
tri.RAng := (rang1 or rang2 or rang3); | |
acute1 := (tri.len[0]<sqrt(sqr(tri.len[1])+sqr(tri.len[2]))); | |
acute2 := (tri.len[1]<sqrt(sqr(tri.len[0])+sqr(tri.len[2]))); | |
acute3 := (tri.len[2]<sqrt(sqr(tri.len[1])+sqr(tri.len[0]))); | |
tri.Refl := (acute1 or acute2 or acute3); | |
end; | |
procedure triInput(var trinpt:triangle); | |
begin | |
write('Type in the three sides of the triangle '); | |
inputReal(trinpt.len[0],trinpt.len[1],trinpt.len[2]); | |
end; | |
{Splash Screen} | |
procedure splash; | |
begin | |
clrscr; | |
gotoxy(36,12); | |
textcolor(white); | |
write('Triangles'); | |
gotoxy(32,13); | |
textcolor(green); | |
write('by Paul Connolley'); | |
delay(3000); | |
clrscr; | |
textcolor(white); | |
end; | |
{Begin Main Program} | |
begin | |
splash; | |
writeln('Welcome to the triangle calculator'); | |
loop:=true; | |
while (loop=true) do | |
begin | |
textcolor(white); | |
triInput(inTri); | |
TriType(inTri); | |
writeln; | |
writeln('Length Information'); | |
writeln('------------------'); | |
textcolor(lightblue); | |
if (inTri.Equi) then writeln('Equilateral'); | |
if (inTri.Scal) then writeln('Scalene'); | |
if (inTri.Isos) then writeln('Isosceles'); | |
writeln; | |
textcolor(white); | |
writeln('Angle Information'); | |
writeln('------------------'); | |
textcolor(lightblue); | |
if (inTri.RAng) then writeln('Right-angled'); | |
if (inTri.Obtu = true) then writeln('Obtuse'); | |
if (inTri.Refl = true) then writeln('Acute'); | |
textcolor(white); | |
writeln; | |
write('Are you done?y/n - '); | |
textcolor(green); | |
readln(doneyet); | |
if (doneyet='y') then loop:=false; | |
end; | |
end.{End Program} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment