[b][red]This message was edited by anyman at 2004-12-12 3:37:8[/red][/b][hr]
The sample is here
program project;
uses wincrt;
var word : array[1..8,1..5] of char;
i,j,k,score,choice:integer;
secret:array[1..3] of string;
answer : string;
Procedure Initial;
begin
for i:=1 to 8 do
for j:= 1 to 5 do
word[i,j] := '*';
end;
Procedure display;
begin
for i := 1 to 8 do
begin
for j := 1 to 5 do
begin
write(word[i,j]);
end;
writeln;
end;
end;
procedure assign;
begin
{Assign the first secret word}
word[1,1] := '1';
for i := 2 to 8 do
begin
word[i,1] := '?';
end;
{Assign the second sercet word}
word[2,1] := '2';
for j:= 2 to 4 do
begin
word[2,j] := '?';
end;
word[6,1] := '3';
{Assign the third secret word}
for j := 2 to 4 do
begin
word[6,j] := '?';
end;
end;
procedure start;
begin
writeln;
writeln;
writeln;
write('Which word do you want to guess(1,2,3)?');
readln(K);
end;
Procedure Hint1;
var done : boolean;
begin
done := false;
secret[1] := 'CHANGJEI';
writeln;
writeln('Hint 1 : A 8 character word');
writeln('Meaning : The most common chinese typing method');
writeln;
Repeat
write('Enter your answer?');
readln(answer);
If answer = secret[1] then
begin
writeln('You are correct !');
done := true;
end
else
writeln('You are wrong! Try it again!');
until done;
end;
procedure hint2;
var done:boolean;
begin
done:= false;
secret[2] := 'HTML';
writeln;
writeln('Hint 2: A 4 character phrase');
writeln('Meaning : the programming language for the web page');
writeln;
Repeat
write('Enter your answer ?');
readln(answer);
if answer = secret[2] then
begin
writeln('You are correct!');
done := true;
end
else
writeln('You are wrong! Try it again!');
until done;
end;
Procedure Hint3;
var done: boolean;
begin
done := false;
secret[3] := 'JAVA';
writeln;
writeln('Hint 3: A 4 character phrase');
writeln('Meaning : The cross-platform programming language for the dynamic web page');
writeln;
Repeat
write('Enter your answer ?');
readln(answer);
if answer = secret[3] then
begin
writeln('You are correct!');
done := true;
end
else
writeln('You are wrong! Try it again!');
until done;
end;
Begin {main}
initial;
assign;
display;
start;
if k = 1 then
hint1
else
if k = 2 then
hint2
else
if k = 3 then
hint3;
End.
Comments
: The sample is here
: program project;
: uses wincrt;
:
: var word : array[1..8,1..5] of char;
: i,j,k,score,choice:integer;
: secret:array[1..3] of string;
: answer : string;
:
:
: Procedure Initial;
: begin
: for i:=1 to 8 do
: for j:= 1 to 5 do
: word[i,j] := '*';
: end;
:
: Procedure display;
: begin
: for i := 1 to 8 do
: begin
: for j := 1 to 5 do
: begin
: write(word[i,j]);
: end;
: writeln;
: end;
: end;
:
: procedure assign;
: begin
: {Assign the first secret word}
: word[1,1] := '1';
: for i := 2 to 8 do
: begin
: word[i,1] := '?';
: end;
: {Assign the second sercet word}
: word[2,1] := '2';
: for j:= 2 to 4 do
: begin
: word[2,j] := '?';
: end;
: word[6,1] := '3';
: {Assign the third secret word}
: for j := 2 to 4 do
: begin
: word[6,j] := '?';
: end;
: end;
: procedure start;
: begin
: writeln;
: writeln;
: writeln;
: write('Which word do you want to guess(1,2,3)?');
: readln(K);
: end;
:
: Procedure Hint1;
: var done : boolean;
: begin
: done := false;
: secret[1] := 'CHANGJEI';
: writeln;
: writeln('Hint 1 : A 8 character word');
: writeln('Meaning : The most common chinese typing method');
: writeln;
: Repeat
: write('Enter your answer?');
: readln(answer);
: If answer = secret[1] then
: begin
: writeln('You are correct !');
: done := true;
: end
: else
: writeln('You are wrong! Try it again!');
: until done;
: end;
:
: procedure hint2;
: var done:boolean;
: begin
: done:= false;
: secret[2] := 'HTML';
: writeln;
: writeln('Hint 2: A 4 character phrase');
: writeln('Meaning : the programming language for the web page');
: writeln;
: Repeat
: write('Enter your answer ?');
: readln(answer);
: if answer = secret[2] then
: begin
: writeln('You are correct!');
: done := true;
: end
: else
: writeln('You are wrong! Try it again!');
: until done;
: end;
:
: Procedure Hint3;
: var done: boolean;
: begin
: done := false;
: secret[3] := 'JAVA';
: writeln;
: writeln('Hint 3: A 4 character phrase');
: writeln('Meaning : The cross-platform programming language for the dynamic web page');
: writeln;
: Repeat
: write('Enter your answer ?');
: readln(answer);
: if answer = secret[3] then
: begin
: writeln('You are correct!');
: done := true;
: end
: else
: writeln('You are wrong! Try it again!');
: until done;
: end;
:
: Begin {main}
: initial;
: assign;
: display;
: start;
: if k = 1 then
: hint1
: else
: if k = 2 then
: hint2
: else
: if k = 3 then
: hint3;
: End.
:
:
:
:
:
wt can I improve
I donna wt should I do
: : The sample is here
: : program project;
: : uses wincrt;
: :
: : var word : array[1..8,1..5] of char;
: : i,j,k,score,choice:integer;
: : secret:array[1..3] of string;
: : answer : string;
: :
: :
: : Procedure Initial;
: : begin
: : for i:=1 to 8 do
: : for j:= 1 to 5 do
: : word[i,j] := '*';
: : end;
: :
: : Procedure display;
: : begin
: : for i := 1 to 8 do
: : begin
: : for j := 1 to 5 do
: : begin
: : write(word[i,j]);
: : end;
: : writeln;
: : end;
: : end;
: :
: : procedure assign;
: : begin
: : {Assign the first secret word}
: : word[1,1] := '1';
: : for i := 2 to 8 do
: : begin
: : word[i,1] := '?';
: : end;
: : {Assign the second sercet word}
: : word[2,1] := '2';
: : for j:= 2 to 4 do
: : begin
: : word[2,j] := '?';
: : end;
: : word[6,1] := '3';
: : {Assign the third secret word}
: : for j := 2 to 4 do
: : begin
: : word[6,j] := '?';
: : end;
: : end;
: : procedure start;
: : begin
: : writeln;
: : writeln;
: : writeln;
: : write('Which word do you want to guess(1,2,3)?');
: : readln(K);
: : end;
: :
: : Procedure Hint1;
: : var done : boolean;
: : begin
: : done := false;
: : secret[1] := 'CHANGJEI';
: : writeln;
: : writeln('Hint 1 : A 8 character word');
: : writeln('Meaning : The most common chinese typing method');
: : writeln;
: : Repeat
: : write('Enter your answer?');
: : readln(answer);
: : If answer = secret[1] then
: : begin
: : writeln('You are correct !');
: : done := true;
: : end
: : else
: : writeln('You are wrong! Try it again!');
: : until done;
: : end;
: :
: : procedure hint2;
: : var done:boolean;
: : begin
: : done:= false;
: : secret[2] := 'HTML';
: : writeln;
: : writeln('Hint 2: A 4 character phrase');
: : writeln('Meaning : the programming language for the web page');
: : writeln;
: : Repeat
: : write('Enter your answer ?');
: : readln(answer);
: : if answer = secret[2] then
: : begin
: : writeln('You are correct!');
: : done := true;
: : end
: : else
: : writeln('You are wrong! Try it again!');
: : until done;
: : end;
: :
: : Procedure Hint3;
: : var done: boolean;
: : begin
: : done := false;
: : secret[3] := 'JAVA';
: : writeln;
: : writeln('Hint 3: A 4 character phrase');
: : writeln('Meaning : The cross-platform programming language for the dynamic web page');
: : writeln;
: : Repeat
: : write('Enter your answer ?');
: : readln(answer);
: : if answer = secret[3] then
: : begin
: : writeln('You are correct!');
: : done := true;
: : end
: : else
: : writeln('You are wrong! Try it again!');
: : until done;
: : end;
: :
: : Begin {main}
: : initial;
: : assign;
: : display;
: : start;
: : if k = 1 then
: : hint1
: : else
: : if k = 2 then
: : hint2
: : else
: : if k = 3 then
: : hint3;
: : End.
: :
: :
: :
: :
: :
: wt can I improve
: I donna wt should I do
:
You can do the following to improve it:
- Add a loop to the main program so that the user can enter all three words
- Move the hints, words and their location and directions into an array, which generalizes the code
- Add the correct indentation, which makes the code itself more readable by others
: : : The sample is here
: : : program project;
: : : uses wincrt;
: : :
: : : var word : array[1..8,1..5] of char;
: : : i,j,k,score,choice:integer;
: : : secret:array[1..3] of string;
: : : answer : string;
: : :
: : :
: : : Procedure Initial;
: : : begin
: : : for i:=1 to 8 do
: : : for j:= 1 to 5 do
: : : word[i,j] := '*';
: : : end;
: : :
: : : Procedure display;
: : : begin
: : : for i := 1 to 8 do
: : : begin
: : : for j := 1 to 5 do
: : : begin
: : : write(word[i,j]);
: : : end;
: : : writeln;
: : : end;
: : : end;
: : :
: : : procedure assign;
: : : begin
: : : {Assign the first secret word}
: : : word[1,1] := '1';
: : : for i := 2 to 8 do
: : : begin
: : : word[i,1] := '?';
: : : end;
: : : {Assign the second sercet word}
: : : word[2,1] := '2';
: : : for j:= 2 to 4 do
: : : begin
: : : word[2,j] := '?';
: : : end;
: : : word[6,1] := '3';
: : : {Assign the third secret word}
: : : for j := 2 to 4 do
: : : begin
: : : word[6,j] := '?';
: : : end;
: : : end;
: : : procedure start;
: : : begin
: : : writeln;
: : : writeln;
: : : writeln;
: : : write('Which word do you want to guess(1,2,3)?');
: : : readln(K);
: : : end;
: : :
: : : Procedure Hint1;
: : : var done : boolean;
: : : begin
: : : done := false;
: : : secret[1] := 'CHANGJEI';
: : : writeln;
: : : writeln('Hint 1 : A 8 character word');
: : : writeln('Meaning : The most common chinese typing method');
: : : writeln;
: : : Repeat
: : : write('Enter your answer?');
: : : readln(answer);
: : : If answer = secret[1] then
: : : begin
: : : writeln('You are correct !');
: : : done := true;
: : : end
: : : else
: : : writeln('You are wrong! Try it again!');
: : : until done;
: : : end;
: : :
: : : procedure hint2;
: : : var done:boolean;
: : : begin
: : : done:= false;
: : : secret[2] := 'HTML';
: : : writeln;
: : : writeln('Hint 2: A 4 character phrase');
: : : writeln('Meaning : the programming language for the web page');
: : : writeln;
: : : Repeat
: : : write('Enter your answer ?');
: : : readln(answer);
: : : if answer = secret[2] then
: : : begin
: : : writeln('You are correct!');
: : : done := true;
: : : end
: : : else
: : : writeln('You are wrong! Try it again!');
: : : until done;
: : : end;
: : :
: : : Procedure Hint3;
: : : var done: boolean;
: : : begin
: : : done := false;
: : : secret[3] := 'JAVA';
: : : writeln;
: : : writeln('Hint 3: A 4 character phrase');
: : : writeln('Meaning : The cross-platform programming language for the dynamic web page');
: : : writeln;
: : : Repeat
: : : write('Enter your answer ?');
: : : readln(answer);
: : : if answer = secret[3] then
: : : begin
: : : writeln('You are correct!');
: : : done := true;
: : : end
: : : else
: : : writeln('You are wrong! Try it again!');
: : : until done;
: : : end;
: : :
: : : Begin {main}
: : : initial;
: : : assign;
: : : display;
: : : start;
: : : if k = 1 then
: : : hint1
: : : else
: : : if k = 2 then
: : : hint2
: : : else
: : : if k = 3 then
: : : hint3;
: : : End.
: : :
: : :
: : :
: : :
: : :
: : wt can I improve
: : I donna wt should I do
: :
: You can do the following to improve it:
: - Add a loop to the main program so that the user can enter all three words
: - Move the hints, words and their location and directions into an array, which generalizes the code
: - Add the correct indentation, which makes the code itself more readable by others
:
:
well
I don't know how to add your suggestion into the program
can u help me
: : : : The sample is here
: : : : program project;
: : : : uses wincrt;
: : : :
: : : : var word : array[1..8,1..5] of char;
: : : : i,j,k,score,choice:integer;
: : : : secret:array[1..3] of string;
: : : : answer : string;
: : : :
: : : :
: : : : Procedure Initial;
: : : : begin
: : : : for i:=1 to 8 do
: : : : for j:= 1 to 5 do
: : : : word[i,j] := '*';
: : : : end;
: : : :
: : : : Procedure display;
: : : : begin
: : : : for i := 1 to 8 do
: : : : begin
: : : : for j := 1 to 5 do
: : : : begin
: : : : write(word[i,j]);
: : : : end;
: : : : writeln;
: : : : end;
: : : : end;
: : : :
: : : : procedure assign;
: : : : begin
: : : : {Assign the first secret word}
: : : : word[1,1] := '1';
: : : : for i := 2 to 8 do
: : : : begin
: : : : word[i,1] := '?';
: : : : end;
: : : : {Assign the second sercet word}
: : : : word[2,1] := '2';
: : : : for j:= 2 to 4 do
: : : : begin
: : : : word[2,j] := '?';
: : : : end;
: : : : word[6,1] := '3';
: : : : {Assign the third secret word}
: : : : for j := 2 to 4 do
: : : : begin
: : : : word[6,j] := '?';
: : : : end;
: : : : end;
: : : : procedure start;
: : : : begin
: : : : writeln;
: : : : writeln;
: : : : writeln;
: : : : write('Which word do you want to guess(1,2,3)?');
: : : : readln(K);
: : : : end;
: : : :
: : : : Procedure Hint1;
: : : : var done : boolean;
: : : : begin
: : : : done := false;
: : : : secret[1] := 'CHANGJEI';
: : : : writeln;
: : : : writeln('Hint 1 : A 8 character word');
: : : : writeln('Meaning : The most common chinese typing method');
: : : : writeln;
: : : : Repeat
: : : : write('Enter your answer?');
: : : : readln(answer);
: : : : If answer = secret[1] then
: : : : begin
: : : : writeln('You are correct !');
: : : : done := true;
: : : : end
: : : : else
: : : : writeln('You are wrong! Try it again!');
: : : : until done;
: : : : end;
: : : :
: : : : procedure hint2;
: : : : var done:boolean;
: : : : begin
: : : : done:= false;
: : : : secret[2] := 'HTML';
: : : : writeln;
: : : : writeln('Hint 2: A 4 character phrase');
: : : : writeln('Meaning : the programming language for the web page');
: : : : writeln;
: : : : Repeat
: : : : write('Enter your answer ?');
: : : : readln(answer);
: : : : if answer = secret[2] then
: : : : begin
: : : : writeln('You are correct!');
: : : : done := true;
: : : : end
: : : : else
: : : : writeln('You are wrong! Try it again!');
: : : : until done;
: : : : end;
: : : :
: : : : Procedure Hint3;
: : : : var done: boolean;
: : : : begin
: : : : done := false;
: : : : secret[3] := 'JAVA';
: : : : writeln;
: : : : writeln('Hint 3: A 4 character phrase');
: : : : writeln('Meaning : The cross-platform programming language for the dynamic web page');
: : : : writeln;
: : : : Repeat
: : : : write('Enter your answer ?');
: : : : readln(answer);
: : : : if answer = secret[3] then
: : : : begin
: : : : writeln('You are correct!');
: : : : done := true;
: : : : end
: : : : else
: : : : writeln('You are wrong! Try it again!');
: : : : until done;
: : : : end;
: : : :
: : : : Begin {main}
: : : : initial;
: : : : assign;
: : : : display;
: : : : start;
: : : : if k = 1 then
: : : : hint1
: : : : else
: : : : if k = 2 then
: : : : hint2
: : : : else
: : : : if k = 3 then
: : : : hint3;
: : : : End.
: : : :
: : : :
: : : :
: : : :
: : : :
: : : wt can I improve
: : : I donna wt should I do
: : :
: : You can do the following to improve it:
: : - Add a loop to the main program so that the user can enter all three words
: : - Move the hints, words and their location and directions into an array, which generalizes the code
: : - Add the correct indentation, which makes the code itself more readable by others
: :
: :
: well
: I don't know how to add your suggestion into the program
: can u help me
:
Adding a loop to the main program should not be a problem, because you've done it before in procedures.
If you know what indentation is (see english dictionary and my Crossword puzzle), then that should also not be a problem.
You are already using the array to store your words in, but only for a short time. You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
: : : : : The sample is here
: : : : : program project;
: : : : : uses wincrt;
: : : : :
: : : : : var word : array[1..8,1..5] of char;
: : : : : i,j,k,score,choice:integer;
: : : : : secret:array[1..3] of string;
: : : : : answer : string;
: : : : :
: : : : :
: : : : : Procedure Initial;
: : : : : begin
: : : : : for i:=1 to 8 do
: : : : : for j:= 1 to 5 do
: : : : : word[i,j] := '*';
: : : : : end;
: : : : :
: : : : : Procedure display;
: : : : : begin
: : : : : for i := 1 to 8 do
: : : : : begin
: : : : : for j := 1 to 5 do
: : : : : begin
: : : : : write(word[i,j]);
: : : : : end;
: : : : : writeln;
: : : : : end;
: : : : : end;
: : : : :
: : : : : procedure assign;
: : : : : begin
: : : : : {Assign the first secret word}
: : : : : word[1,1] := '1';
: : : : : for i := 2 to 8 do
: : : : : begin
: : : : : word[i,1] := '?';
: : : : : end;
: : : : : {Assign the second sercet word}
: : : : : word[2,1] := '2';
: : : : : for j:= 2 to 4 do
: : : : : begin
: : : : : word[2,j] := '?';
: : : : : end;
: : : : : word[6,1] := '3';
: : : : : {Assign the third secret word}
: : : : : for j := 2 to 4 do
: : : : : begin
: : : : : word[6,j] := '?';
: : : : : end;
: : : : : end;
: : : : : procedure start;
: : : : : begin
: : : : : writeln;
: : : : : writeln;
: : : : : writeln;
: : : : : write('Which word do you want to guess(1,2,3)?');
: : : : : readln(K);
: : : : : end;
: : : : :
: : : : : Procedure Hint1;
: : : : : var done : boolean;
: : : : : begin
: : : : : done := false;
: : : : : secret[1] := 'CHANGJEI';
: : : : : writeln;
: : : : : writeln('Hint 1 : A 8 character word');
: : : : : writeln('Meaning : The most common chinese typing method');
: : : : : writeln;
: : : : : Repeat
: : : : : write('Enter your answer?');
: : : : : readln(answer);
: : : : : If answer = secret[1] then
: : : : : begin
: : : : : writeln('You are correct !');
: : : : : done := true;
: : : : : end
: : : : : else
: : : : : writeln('You are wrong! Try it again!');
: : : : : until done;
: : : : : end;
: : : : :
: : : : : procedure hint2;
: : : : : var done:boolean;
: : : : : begin
: : : : : done:= false;
: : : : : secret[2] := 'HTML';
: : : : : writeln;
: : : : : writeln('Hint 2: A 4 character phrase');
: : : : : writeln('Meaning : the programming language for the web page');
: : : : : writeln;
: : : : : Repeat
: : : : : write('Enter your answer ?');
: : : : : readln(answer);
: : : : : if answer = secret[2] then
: : : : : begin
: : : : : writeln('You are correct!');
: : : : : done := true;
: : : : : end
: : : : : else
: : : : : writeln('You are wrong! Try it again!');
: : : : : until done;
: : : : : end;
: : : : :
: : : : : Procedure Hint3;
: : : : : var done: boolean;
: : : : : begin
: : : : : done := false;
: : : : : secret[3] := 'JAVA';
: : : : : writeln;
: : : : : writeln('Hint 3: A 4 character phrase');
: : : : : writeln('Meaning : The cross-platform programming language for the dynamic web page');
: : : : : writeln;
: : : : : Repeat
: : : : : write('Enter your answer ?');
: : : : : readln(answer);
: : : : : if answer = secret[3] then
: : : : : begin
: : : : : writeln('You are correct!');
: : : : : done := true;
: : : : : end
: : : : : else
: : : : : writeln('You are wrong! Try it again!');
: : : : : until done;
: : : : : end;
: : : : :
: : : : : Begin {main}
: : : : : initial;
: : : : : assign;
: : : : : display;
: : : : : start;
: : : : : if k = 1 then
: : : : : hint1
: : : : : else
: : : : : if k = 2 then
: : : : : hint2
: : : : : else
: : : : : if k = 3 then
: : : : : hint3;
: : : : : End.
: : : : :
: : : : :
: : : : :
: : : : :
: : : : :
: : : : wt can I improve
: : : : I donna wt should I do
: : : :
: : : You can do the following to improve it:
: : : - Add a loop to the main program so that the user can enter all three words
: : : - Move the hints, words and their location and directions into an array, which generalizes the code
: : : - Add the correct indentation, which makes the code itself more readable by others
: : :
: : :
: : well
: : I don't know how to add your suggestion into the program
: : can u help me
: :
: Adding a loop to the main program should not be a problem, because you've done it before in procedures.
: If you know what indentation is (see english dictionary and my Crossword puzzle), then that should also not be a problem.
: You are already using the array to store your words in, but only for a short time. You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
:
You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
I don't exactly know what u mean
Do u think that if I make the word into wordfile will be better
by the way, do u hv e-mail,msn , icq or something like that, so I can contact u
: : : : : : The sample is here
: : : : : : program project;
: : : : : : uses wincrt;
: : : : : :
: : : : : : var word : array[1..8,1..5] of char;
: : : : : : i,j,k,score,choice:integer;
: : : : : : secret:array[1..3] of string;
: : : : : : answer : string;
: : : : : :
: : : : : :
: : : : : : Procedure Initial;
: : : : : : begin
: : : : : : for i:=1 to 8 do
: : : : : : for j:= 1 to 5 do
: : : : : : word[i,j] := '*';
: : : : : : end;
: : : : : :
: : : : : : Procedure display;
: : : : : : begin
: : : : : : for i := 1 to 8 do
: : : : : : begin
: : : : : : for j := 1 to 5 do
: : : : : : begin
: : : : : : write(word[i,j]);
: : : : : : end;
: : : : : : writeln;
: : : : : : end;
: : : : : : end;
: : : : : :
: : : : : : procedure assign;
: : : : : : begin
: : : : : : {Assign the first secret word}
: : : : : : word[1,1] := '1';
: : : : : : for i := 2 to 8 do
: : : : : : begin
: : : : : : word[i,1] := '?';
: : : : : : end;
: : : : : : {Assign the second sercet word}
: : : : : : word[2,1] := '2';
: : : : : : for j:= 2 to 4 do
: : : : : : begin
: : : : : : word[2,j] := '?';
: : : : : : end;
: : : : : : word[6,1] := '3';
: : : : : : {Assign the third secret word}
: : : : : : for j := 2 to 4 do
: : : : : : begin
: : : : : : word[6,j] := '?';
: : : : : : end;
: : : : : : end;
: : : : : : procedure start;
: : : : : : begin
: : : : : : writeln;
: : : : : : writeln;
: : : : : : writeln;
: : : : : : write('Which word do you want to guess(1,2,3)?');
: : : : : : readln(K);
: : : : : : end;
: : : : : :
: : : : : : Procedure Hint1;
: : : : : : var done : boolean;
: : : : : : begin
: : : : : : done := false;
: : : : : : secret[1] := 'CHANGJEI';
: : : : : : writeln;
: : : : : : writeln('Hint 1 : A 8 character word');
: : : : : : writeln('Meaning : The most common chinese typing method');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer?');
: : : : : : readln(answer);
: : : : : : If answer = secret[1] then
: : : : : : begin
: : : : : : writeln('You are correct !');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : procedure hint2;
: : : : : : var done:boolean;
: : : : : : begin
: : : : : : done:= false;
: : : : : : secret[2] := 'HTML';
: : : : : : writeln;
: : : : : : writeln('Hint 2: A 4 character phrase');
: : : : : : writeln('Meaning : the programming language for the web page');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer ?');
: : : : : : readln(answer);
: : : : : : if answer = secret[2] then
: : : : : : begin
: : : : : : writeln('You are correct!');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : Procedure Hint3;
: : : : : : var done: boolean;
: : : : : : begin
: : : : : : done := false;
: : : : : : secret[3] := 'JAVA';
: : : : : : writeln;
: : : : : : writeln('Hint 3: A 4 character phrase');
: : : : : : writeln('Meaning : The cross-platform programming language for the dynamic web page');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer ?');
: : : : : : readln(answer);
: : : : : : if answer = secret[3] then
: : : : : : begin
: : : : : : writeln('You are correct!');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : Begin {main}
: : : : : : initial;
: : : : : : assign;
: : : : : : display;
: : : : : : start;
: : : : : : if k = 1 then
: : : : : : hint1
: : : : : : else
: : : : : : if k = 2 then
: : : : : : hint2
: : : : : : else
: : : : : : if k = 3 then
: : : : : : hint3;
: : : : : : End.
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : wt can I improve
: : : : : I donna wt should I do
: : : : :
: : : : You can do the following to improve it:
: : : : - Add a loop to the main program so that the user can enter all three words
: : : : - Move the hints, words and their location and directions into an array, which generalizes the code
: : : : - Add the correct indentation, which makes the code itself more readable by others
: : : :
: : : :
: : : well
: : : I don't know how to add your suggestion into the program
: : : can u help me
: : :
: : Adding a loop to the main program should not be a problem, because you've done it before in procedures.
: : If you know what indentation is (see english dictionary and my Crossword puzzle), then that should also not be a problem.
: : You are already using the array to store your words in, but only for a short time. You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
: :
:
: You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
: I don't exactly know what u mean
: Do u think that if I make the word into wordfile will be better
: by the way, do u hv e-mail,msn , icq or something like that, so I can contact u
:
Interesting! Can I also have one?
e-mail:henry_hk007@yahoo.com.hk
: : : : : : The sample is here
: : : : : : program project;
: : : : : : uses wincrt;
: : : : : :
: : : : : : var word : array[1..8,1..5] of char;
: : : : : : i,j,k,score,choice:integer;
: : : : : : secret:array[1..3] of string;
: : : : : : answer : string;
: : : : : :
: : : : : :
: : : : : : Procedure Initial;
: : : : : : begin
: : : : : : for i:=1 to 8 do
: : : : : : for j:= 1 to 5 do
: : : : : : word[i,j] := '*';
: : : : : : end;
: : : : : :
: : : : : : Procedure display;
: : : : : : begin
: : : : : : for i := 1 to 8 do
: : : : : : begin
: : : : : : for j := 1 to 5 do
: : : : : : begin
: : : : : : write(word[i,j]);
: : : : : : end;
: : : : : : writeln;
: : : : : : end;
: : : : : : end;
: : : : : :
: : : : : : procedure assign;
: : : : : : begin
: : : : : : {Assign the first secret word}
: : : : : : word[1,1] := '1';
: : : : : : for i := 2 to 8 do
: : : : : : begin
: : : : : : word[i,1] := '?';
: : : : : : end;
: : : : : : {Assign the second sercet word}
: : : : : : word[2,1] := '2';
: : : : : : for j:= 2 to 4 do
: : : : : : begin
: : : : : : word[2,j] := '?';
: : : : : : end;
: : : : : : word[6,1] := '3';
: : : : : : {Assign the third secret word}
: : : : : : for j := 2 to 4 do
: : : : : : begin
: : : : : : word[6,j] := '?';
: : : : : : end;
: : : : : : end;
: : : : : : procedure start;
: : : : : : begin
: : : : : : writeln;
: : : : : : writeln;
: : : : : : writeln;
: : : : : : write('Which word do you want to guess(1,2,3)?');
: : : : : : readln(K);
: : : : : : end;
: : : : : :
: : : : : : Procedure Hint1;
: : : : : : var done : boolean;
: : : : : : begin
: : : : : : done := false;
: : : : : : secret[1] := 'CHANGJEI';
: : : : : : writeln;
: : : : : : writeln('Hint 1 : A 8 character word');
: : : : : : writeln('Meaning : The most common chinese typing method');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer?');
: : : : : : readln(answer);
: : : : : : If answer = secret[1] then
: : : : : : begin
: : : : : : writeln('You are correct !');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : procedure hint2;
: : : : : : var done:boolean;
: : : : : : begin
: : : : : : done:= false;
: : : : : : secret[2] := 'HTML';
: : : : : : writeln;
: : : : : : writeln('Hint 2: A 4 character phrase');
: : : : : : writeln('Meaning : the programming language for the web page');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer ?');
: : : : : : readln(answer);
: : : : : : if answer = secret[2] then
: : : : : : begin
: : : : : : writeln('You are correct!');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : Procedure Hint3;
: : : : : : var done: boolean;
: : : : : : begin
: : : : : : done := false;
: : : : : : secret[3] := 'JAVA';
: : : : : : writeln;
: : : : : : writeln('Hint 3: A 4 character phrase');
: : : : : : writeln('Meaning : The cross-platform programming language for the dynamic web page');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer ?');
: : : : : : readln(answer);
: : : : : : if answer = secret[3] then
: : : : : : begin
: : : : : : writeln('You are correct!');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : Begin {main}
: : : : : : initial;
: : : : : : assign;
: : : : : : display;
: : : : : : start;
: : : : : : if k = 1 then
: : : : : : hint1
: : : : : : else
: : : : : : if k = 2 then
: : : : : : hint2
: : : : : : else
: : : : : : if k = 3 then
: : : : : : hint3;
: : : : : : End.
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : wt can I improve
: : : : : I donna wt should I do
: : : : :
: : : : You can do the following to improve it:
: : : : - Add a loop to the main program so that the user can enter all three words
: : : : - Move the hints, words and their location and directions into an array, which generalizes the code
: : : : - Add the correct indentation, which makes the code itself more readable by others
: : : :
: : : :
: : : well
: : : I don't know how to add your suggestion into the program
: : : can u help me
: : :
: : Adding a loop to the main program should not be a problem, because you've done it before in procedures.
: : If you know what indentation is (see english dictionary and my Crossword puzzle), then that should also not be a problem.
: : You are already using the array to store your words in, but only for a short time. You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
: :
:
: You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
: I don't exactly know what u mean
: Do u think that if I make the word into wordfile will be better
: by the way, do u hv e-mail,msn , icq or something like that, so I can contact u
:
The ways to contact me are listed on my page here at PH.
A Pascal assignment is a line with uses this symbol: [b]:=[/b]
In your code (in the Hint# procedures) you have various codes like this:
[code]
secret[3] := 'JAVA';
[/code]
If you move these to the Initial() procedure and create an array for the hints, you can delete 2 of the Hint#() procedures and only have a single Hint() procedure, which uses these arrays and the k variable.
: The ways to contact me are listed on my page here at PH.
"here at PH"? Where do you mean?
What is PH?
Thank you
: : The ways to contact me are listed on my page here at PH.
:
: "here at PH"? Where do you mean?
: What is PH?
: Thank you
:
With PH I mean ProgrammersHeaven.
: : : The ways to contact me are listed on my page here at PH.
: :
: : "here at PH"? Where do you mean?
: : What is PH?
: : Thank you
: :
: With PH I mean ProgrammersHeaven.
:
how can i readin data from the textfile in the random way
and also how can i receive answer in both upper and lower letters
: : :
: : : : The ways to contact me are listed on my page here at PH.
: : :
: : : "here at PH"? Where do you mean?
: : : What is PH?
: : : Thank you
: : :
: : With PH I mean ProgrammersHeaven.
: :
: how can i readin data from the textfile in the random way
: and also how can i receive answer in both upper and lower letters
:
Some more questions
I still can't figure out when should I use array
and how many arrays should I use
[code]
program project;
uses wincrt;
var i,n,score,choice:integer;
puzzle:text;
word:array[1..20,1..20] of char;
ans:array[1..20] of string;
display:array[1..20] of string;
Procedure Loading;
begin
assign(puzzle,'puzzle1.txt');
reset(puzzle);
n:=1;
while not eof(puzzle) do
begin
readln(puzzle,display[n]);
n:=n+1
end;
n:=n-1;
end;
begin{main};
Loading;
end.
[/code]
why I can use this program to read the data that I type in textfile a display
: : : : : : The sample is here
: : : : : : program project;
: : : : : : uses wincrt;
: : : : : :
: : : : : : var word : array[1..8,1..5] of char;
: : : : : : i,j,k,score,choice:integer;
: : : : : : secret:array[1..3] of string;
: : : : : : answer : string;
: : : : : :
: : : : : :
: : : : : : Procedure Initial;
: : : : : : begin
: : : : : : for i:=1 to 8 do
: : : : : : for j:= 1 to 5 do
: : : : : : word[i,j] := '*';
: : : : : : end;
: : : : : :
: : : : : : Procedure display;
: : : : : : begin
: : : : : : for i := 1 to 8 do
: : : : : : begin
: : : : : : for j := 1 to 5 do
: : : : : : begin
: : : : : : write(word[i,j]);
: : : : : : end;
: : : : : : writeln;
: : : : : : end;
: : : : : : end;
: : : : : :
: : : : : : procedure assign;
: : : : : : begin
: : : : : : {Assign the first secret word}
: : : : : : word[1,1] := '1';
: : : : : : for i := 2 to 8 do
: : : : : : begin
: : : : : : word[i,1] := '?';
: : : : : : end;
: : : : : : {Assign the second sercet word}
: : : : : : word[2,1] := '2';
: : : : : : for j:= 2 to 4 do
: : : : : : begin
: : : : : : word[2,j] := '?';
: : : : : : end;
: : : : : : word[6,1] := '3';
: : : : : : {Assign the third secret word}
: : : : : : for j := 2 to 4 do
: : : : : : begin
: : : : : : word[6,j] := '?';
: : : : : : end;
: : : : : : end;
: : : : : : procedure start;
: : : : : : begin
: : : : : : writeln;
: : : : : : writeln;
: : : : : : writeln;
: : : : : : write('Which word do you want to guess(1,2,3)?');
: : : : : : readln(K);
: : : : : : end;
: : : : : :
: : : : : : Procedure Hint1;
: : : : : : var done : boolean;
: : : : : : begin
: : : : : : done := false;
: : : : : : secret[1] := 'CHANGJEI';
: : : : : : writeln;
: : : : : : writeln('Hint 1 : A 8 character word');
: : : : : : writeln('Meaning : The most common chinese typing method');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer?');
: : : : : : readln(answer);
: : : : : : If answer = secret[1] then
: : : : : : begin
: : : : : : writeln('You are correct !');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : procedure hint2;
: : : : : : var done:boolean;
: : : : : : begin
: : : : : : done:= false;
: : : : : : secret[2] := 'HTML';
: : : : : : writeln;
: : : : : : writeln('Hint 2: A 4 character phrase');
: : : : : : writeln('Meaning : the programming language for the web page');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer ?');
: : : : : : readln(answer);
: : : : : : if answer = secret[2] then
: : : : : : begin
: : : : : : writeln('You are correct!');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : Procedure Hint3;
: : : : : : var done: boolean;
: : : : : : begin
: : : : : : done := false;
: : : : : : secret[3] := 'JAVA';
: : : : : : writeln;
: : : : : : writeln('Hint 3: A 4 character phrase');
: : : : : : writeln('Meaning : The cross-platform programming language for the dynamic web page');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer ?');
: : : : : : readln(answer);
: : : : : : if answer = secret[3] then
: : : : : : begin
: : : : : : writeln('You are correct!');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : Begin {main}
: : : : : : initial;
: : : : : : assign;
: : : : : : display;
: : : : : : start;
: : : : : : if k = 1 then
: : : : : : hint1
: : : : : : else
: : : : : : if k = 2 then
: : : : : : hint2
: : : : : : else
: : : : : : if k = 3 then
: : : : : : hint3;
: : : : : : End.
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : wt can I improve
: : : : : I donna wt should I do
: : : : :
: : : : You can do the following to improve it:
: : : : - Add a loop to the main program so that the user can enter all three words
: : : : - Move the hints, words and their location and directions into an array, which generalizes the code
: : : : - Add the correct indentation, which makes the code itself more readable by others
: : : :
: : : :
: : : well
: : : I don't know how to add your suggestion into the program
: : : can u help me
: : :
: : Adding a loop to the main program should not be a problem, because you've done it before in procedures.
: : If you know what indentation is (see english dictionary and my Crossword puzzle), then that should also not be a problem.
: : You are already using the array to store your words in, but only for a short time. You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
: :
:
: You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
: I don't exactly know what u mean
: Do u think that if I make the word into wordfile will be better
: by the way, do u hv e-mail,msn , icq or something like that, so I can contact u
:
An array is mostly used as a list of variables. The main advantage of an array over a true list of variables is that you can use other variables to control which array element you get.
For example:
This code
[code]
var
Number1, Number2, Number3, Number4, Number5: integer;
Sum: integer;
UserEntry: integer;
begin
Sum := Number1 + Number2 + Number3 + Number4 + Number5;
{...}
readln(UserEntry);
if UserEntry = 1 then
writeln(Number1)
else if UserEntry = 2 then
writeln(Number2)
else if UserEntry = 3 then
writeln(Number3)
else if UserEntry = 4 then
writeln(Number4)
else if UserEntry = 5 then
writeln(Number5);
end.
[/code]
and this code give the same result:
[code]
const
NumberOfNumbers = 5;
var
Numbers: array[1..NumberOfNumbers] of integer;
Sum, i: integer;
begin
Sum := 0;
for i := 1 to NumberOfNumbers do
Sum := Sum + Numbers[i];
{...}
readln(UserEntry);
writeln(Numbers[UserEntry]);
end.
[/code]
The main difference from a programmer's perspective is that the latter is far easier to modify. Suppose you want to expand the sum to 100 numbers. In the first case, you would need to create 95 additional variables. Then recode the calculation to include those 95 numbers. Also you need to change add 95 time the following 2 lines:
[code]
else if UserEntry = 5 then
writeln(Number5);
[/code]
and change the 5 into a 6, 7, 8, etc.
In the second case, you just change the value of NumberOfNumbers to 100 and you're done.
As to the number of arrays, that completely depends on the way you want to store your data. I've used 1 array for all the words, hints and locations. And another one for the display of the game. I was able to do this, because I know about records. In your case I would use more than 2 arrays:
- Words
- Hints
- Locations (2-dimensional array)
- IsVertical
- Display
: : : : The ways to contact me are listed on my page here at PH.
: : :
: : : "here at PH"? Where do you mean?
: : : What is PH?
: : : Thank you
: : :
: : With PH I mean ProgrammersHeaven.
: :
: how can i readin data from the textfile in the random way
: and also how can i receive answer in both upper and lower letters
:
Load the textfile into an array and then sort that array using Random() as method to compare the elements.
This is shown in CheckAnswer().
I can't show the text and the symbol in the text file that I typed
wt is the problem