pascal help
•
2 Mar 2009, 17:00
•
Journals
Hi hi.
I'm in need of help. I'd like to make this program but doesn't really seem to work.
I'll try to explain what I want.
The program gives a random number between 1-100, and you have to write another one(stintless) and we need the square(smaller number to the power two) of the smaller number.
(using function)
program test;
uses crt,
var
a,b:integer;
function square(szam1,szam2:integer) : integer;
begin
if szam1<szam2 then write(sqr(szam1))
else write(sqr(szam2));
end;
begin
clrscr;
randomize;
b:=random(101); write(a);
writeln;
writeln('2nd number:'); readln(b);
write('smaller number to the power two:', square(??);
readln;
end.
I tried to write square(a,b) then it gives the result of both number.
I hope you understand this way of explanation :D Sorry for my english :)
Let me know what's wrong there :(
I'm in need of help. I'd like to make this program but doesn't really seem to work.
I'll try to explain what I want.
The program gives a random number between 1-100, and you have to write another one(stintless) and we need the square(smaller number to the power two) of the smaller number.
(using function)
program test;
uses crt,
var
a,b:integer;
function square(szam1,szam2:integer) : integer;
begin
if szam1<szam2 then write(sqr(szam1))
else write(sqr(szam2));
end;
begin
clrscr;
randomize;
b:=random(101); write(a);
writeln;
writeln('2nd number:'); readln(b);
write('smaller number to the power two:', square(??);
readln;
end.
I tried to write square(a,b) then it gives the result of both number.
I hope you understand this way of explanation :D Sorry for my english :)
Let me know what's wrong there :(
writeln('2nd number:'); readln(b);, letting the user overwrite the value of b, doesnt make any sence.
a:=random(101);
writeln('2nd number:'); readln(b);
write('smaller number to the power two:', square(a,b);
Been very long since I did any programming in Pascal, so Im not 100% sure it will work
uses crt;
var
a,b:integer;
procedure square(szam1,szam2:integer);
begin
if szam1<szam2 then write(sqr(szam1))
else write(sqr(szam2));
end;
begin
clrscr;
randomize;
a:=random(101);
write(a);
writeln;
writeln('2nd number:'); readln(b);
write('smaller number to the power two:');
square(a,b);
readln;
end.
Edit: Im awesome, except for the small detail that I forgot the syntax for functions so I used a procedure instead :(
If you're still using your old code I think the problem might be that you never set a value for a, which results in something random.
Thanks mate!
But everyone in my school read some basic programming.
And why would it be so strange if I were a girl who was interested in computer stuff, like programming?
in fuction i had to set this:
if szam1<szam2 then square:=sqr(szam1)
else square:=sqr(szam2);**
:))