So Delphi 7 is giving me problems with this code:
Code:
if (c mod 1 = 0) then
The debugger says: "Operator not applicable to this operand type."
Why is it not applicable (c is a real number)?
I'm writing a program to find integer solutions to the Pythagorean theorem (i.e. 3, 4, 5), so I need some way to find out if c is an integer or not (hence the code above). If c happens to be 5, then there will be no remainder, but if it happens to be the square root of 2, it will have .141... as a remainder, and I'll discard it. Is there some way I can get the above code to work? Another way to find out if a number is an integer or not, perhaps?
I really hope you can help. Thanks a lot!
(Here's the whole code, if anyone's interested)
Code:
program Pythagorean_Integral_Solution_Finder;
{$APPTYPE CONSOLE}
{Daniel Young
August 8, 2009
Find integral solutions to the Pythagorean theorem
}
uses
SysUtils;
var
a : integer;
b : integer;
c : real;
n : integer;
begin
writeln('***Pythagorean Integral Tester***':50);
write('Enter the biggest number you want a and b to be tested to');
write(' in the formula a^2 + b^2 = c^2: ');
readln(n);
a := 1;
b := 1;
c := 0;
while (b < (n+1)) do
begin
while (a < (n+1)) do
begin
c := sqrt(sqr(a) + sqr(b));
if (c mod 1 = 0) then
begin
writeln(a, ' ', b, ' ', c, ' ');
a := a + 1;
end
else
a := a + 1;
end;
b := b + 1;
a := 1;
end;
readln;
end.[quote][/quote]