Link to home
Start Free TrialLog in
Avatar of The_ARA
The_ARA

asked on

Pascal assignment , need help :(

Write a program that;

Prompts and permits the user to enter a phrase.

Prompts and permits the user to enter a word.

Reveals the number of times that the word occurs in the phrase.  (N.B.  Words within words do not count).

ive tried so far

program INPHRASE;
uses crt;
var
word : string;
phrase : string;
i : integer;
c : integer;
begin
clrscr;
write('Enter a phrase : ');
readln(phrase);
writeln;
write('Enter a word : ');
readln(word);
c :=0;
for i := 1 to length(phrase) Do
if phrase[i] = word then c := c+1;
writeln;
writeln('Found word "'+word+'" in phrase "'+phrase+'" ',c,' times.');
readln;
end.

Please help
ASKER CERTIFIED SOLUTION
Avatar of VGR
VGR

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VGR
VGR

it's lacking to skip the space found in the loop, and perhaps failing to treat the last word, but the general idea is this.

I suppose that for a "homework help" it's enough to provide almost-good solutions ;-)
Maybe you're able to scan for the Word expression in a string with POS.
Then copy the Rest of the String
Now Repat Expression scan and rest-copy process till the end of String.
Do this like you want!
I'm sure you're able to.
Maybe you're able to scan for the Word expression in a string with POS.
Then copy the Rest of the String
Now Repat Expression scan and rest-copy process till the end of String.
Do this like you want!
I'm sure you're able to.