Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi I'm trying to write a little program that shows functions. The first bit works ok:
var
value : char;
number: real;
numberint : integer;procedure get_chr;
{returns function value of character}
begin
Write ('Please enter a letter or number:');
readln(value);
writeln;
writeln ('Function succ means value is ',(succ(value)));
writeln;
writeln ('Function pred means value is ',(pred(value)));
writeln;
writeln ('Function ord means value is ',(ord(value)));
writeln;
writeln ('Function upcase means value is ',(upcase(value)));end;
procedure function_numbers;
{shows functions that require numeric input}
begin
write ('Please enter a number : ');
readln (number);
writeln ('Function abs means number is ',(round(number)));
writeln;
writeln ('Function odd means number is ',(odd(numberint)));
writeln;
writeln ('Function (chr(ord)) means number is ',(chr(ord(numberint))));
writeln;
writeln ('Function (ord(chr)) means number is ',(ord(chr(numberint))));
writeln;
writeln ('Function abs means number is ',(abs(number)));
writeln;
writeln ('Function trunc means number is ',(trunc(number)));
writeln;
writeln ('Function sqr means number is ',(sqr(number)));
writeln;
writeln ('Function arctan means number is ',(arctan(number)));
writeln;
writeln ('Function cos means number is ',(cos(number)));
writeln;
writeln ('Function sin means number is ',(sin(number)));
writeln;
writeln ('Function exp means number is ',(exp(numberint)));
writeln;
writeln ('Function ln means number is ',(ln(number)));
writeln;
writeln ('Function chr means number is ',(chr(numberint)));
end;begin {main program}
clrscr;clrscr;
gotoxy (35,10);
writeln ('Press ! to exit');get_chr;
function_numbers;
end.There is a couple of problems with it but the one that's bugging me is how do I format the 'real' numbers like:
writeln ('This function sqr is ', (sqr(numberint:10;3)));
That was just an idea of what I'm trying to do but that's obviously wrong.
Also why is the 'odd' function always returning a value of FALSE even if I input '3' ?
And the (chr(ord(numberint)) and (ord(chr(numberint)) functions return nothing at all.
Anyway it's the 10:3 problem I'm more interested in just now.
Thanks for any replies. :)
But this bit doesn't:

G'day,
The function argument fot odd() is integer.
You are passing it a real, which it could be taking as a 0 which is considered even (because it is between two odd numbers -1 and 1). Just a first thought.
The syntax for reals is:
eg writeln('The square root of ',R:7:7, )
ie 7 int and 7 decimal places.
regards,
elric

G'day,
On second thoughts, you are trying to dettermine if numberint is odd or even, but it doesn't look like you have entered it. Therefore, your compiler might be treating it as zero.]
regards,
Elric

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |