Code:
Function SolveForY(xVal: Integer): Integer;
Solve for Y takes an integer, yet you are passing an extended var.
Code:
Var AX, AY: Extended;
AY := SolveForY(AX);
Just change to:
Code:
Function SolveForY(xVal: Extended): Extended;
Var xTotal,xWork, yVal, cVal, cWork, Answer: Extended;
Code:
Procedure WriteSolution(X, Y: Integer);
This takes an integer, yet you pass an extended.
Edit: I don't have enough time to go through this wholly but here's something that compiles/may work. Look through it:
Code:
program SolutionFinder_2Var;
// Format
// A(x)+B(y)=C
// Input
// A
// B
// C
// First Line
Const A1 = 5;
Const B1 = 3;
Const C1 = 6;
// Second Line
Const A2 = 4;
Const B2 = 5;
Const C2 = 2;
{--------Dont Touch Below This-------------}
Var AX, AY: Integer;
FixedEquations: Array of Array of Integer;
Line: Array [0..1] of Array[0..2] of Integer;
Procedure WriteEquation(TPA: Array of Integer; Name: String);
Var X,Y,C: Integer;
Begin
X := TPA[0];
Y := TPA[1];
C := TPA[2];
WriteLn('Name: ' + Name);
Writeln(IntToStr(X)+'X'+ IntToStr(Y)+'Y'+ '=' + IntToStr(C));
End;
// Changes Both Equations, To Cancel Out the X's
Function FixEquationXs(TPA1, TPA2: Array of Integer): Array of Array of Integer;
Var F, S: Integer;
FirstE, SecondE: Array [0..2] of Integer;
Answer: Array of Array of Integer;
Begin
// Solves by timing the Y's together. Causing them to alway cancel out
// Multiplying The First Equation, Bu TPA2's Y value
S := TPA2[1];
FirstE[0] := (TPA1[0]*S);
FirstE[1] := (TPA1[1]*S);
FirstE[2] := (TPA1[2]*S);
F := TPA1[1];
SecondE[0] := (TPA2[0]*F);
SecondE[0] := (TPA2[0]*F);
SecondE[0] := (TPA2[0]*F);
// Need Y's to be Opposites
SecondE[0] := (SecondE[0]*-1);
SecondE[0] := (SecondE[1]*-1);
SecondE[0] := (SecondE[2]*-1);
Answer := [FirstE, SecondE];
WriteLn('Equations awaiting For Elimination');
WriteEquation(FirstE, 'First Equation');
// WriteEquation(FirstE, 'First Equation');
Result := Answer;
End;
// Sets up Equations, Enabling the Elimination of Y Values
Function SolveForXStep1(TPA1, TPA2: Array of Integer): Array of Array of Integer;
var Answer: Array of Array of Integer;
Begin
If (not(TPA1[0] = TPA2[0])) Then // If x's aren't the same, to begin
Begin
If (Abs(TPA1[0]) = Abs(TPA2[0])) Then // If the problem is Ready to go!
Begin
Answer[0] := TPA1;
Answer[1] := TPA2;
Result := Answer;
Exit;
End;
// Equations need to be fixed!!!
Answer := FixEquationXs(TPA1, TPA2);
Result := Answer;
Exit;
End;
// Y's are the same. Need to Be opposites
//Answer[0] := [TPA1[0], TPA1[1], TPA1[2]];
Answer[0][0] := TPA1[0];
Answer[0][1] := TPA1[1];
Answer[0][2] := TPA1[2];
Answer[1][0] := (TPA2[0]* -1);
Answer[1][1] := (TPA2[1]* -1);
Answer[1][2] := (TPA2[2]* -1);
Result := Answer;
End;
Function SolveForX(Equations: Array of Array of Integer): Integer;
Var X, Y, C, Answer: Integer;
Begin
X := (Equations[0][0] + Equations[1][0]);
Y := (Equations[0][1] + Equations[1][1]);
C := (Equations[0][2] + Equations[1][2]);
// In Case of Both Variables Cancle Out
If ((X=0) And (Y=0)) Then
If (C=0) Then
Begin
WriteLn(' Answer: Infinent Solutions');
//TerminateScript;
End Else
Begin
WriteLn(' Answer: No Solutions');
//TerminateScript;
End;
// In case we didn't use elimination right. Rele, me donig bad scripting
If (Not(Y=0)) Then
Begin
WriteLn('The Eqations did not get solved for X');
//TerminateScript;
End;
Answer := (C/X);
Result := Answer;
End;
Function SolveForY(xVal: Integer): Integer;
Var xTotal,xWork, yVal, cVal, cWork, Answer: Integer;
Begin
xTotal := (xVal*A1);
yVal := B1;
cVal := C1;
xWork := (xTotal*-1);
cWork := (cVal+xWork);
Answer := (cWork/yVal);
Result := Answer;
End;
Procedure WriteSolution(AX, AY: Integer);
Begin
WriteLn('Solution = (' + IntToStr(AX)+ ',' + IntToStr(AY) + ')');
End;
begin
// Setup Variables
Line[0][0] := A1;
Line[0][1] := B1;
Line[0][2] := C1;
Line[1][0] := A2;
Line[1][1] := B2;
Line[1][2] := C2;
//-------------
FixedEquations := SolveForXStep1(Line[0], Line[1]); // Changes equations to have oppisite values
AX := SolveForX(FixedEquations); // Solves to find X value
AY := SolveForY(AX); //E // Solves to find Y value
WriteSolution(AX, AY); // Prints it out
end.