• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

Help with control and strings

I need to Write a program in Turbo pascal that:

a)Prompts and permits the user to enter a word.

b)Prompts and permits the user to enter a letter.

c)Reveals the number of times that the letter occurs in the word.

PLEASE HELP
0
sajidaziz
Asked:
sajidaziz
1 Solution
 
lmikleCommented:
program L_in_W;

var
  W : String;
  L : Char;

  I : Integer;
  C : Integer;

begin
  Write('Enter a letter: ');
  ReadLn(L);
  Write('Enter a word: ');
  ReadLn(W);

  C := 0;
  For I := 1 To Length(W) Do
    If W[I] = L Then C := C+1;

  WriteLn('Found letter "'+L+'" in word "'+W+'" ',C,' times.');
end.
0
 
mlmccCommented:
Good homework exercise!!!

mlmcc
0
 
VGRCommented:
true
you should have done it yourself.
I advise you kindly to look at the (very well written) Pascal online documentation of your compiler.

If you search how to manipoulate chars and string, look at "string" and "char" : you'll find that :
-Strings are 1-based arrays of Chars
-read(c), KeyPressed and ReadLn(c) may be used for user entry (actually, it's readLn(InPut,c) but who cares ? :D

As for counting a number of occurences of a char in a string, the most common idea is to use either a for loop or a while loop, or a repeat-until one. Everything is possible. Just think about it 5 minutes 8-)
0
 
sajidazizAuthor Commented:
Thankyou for your help
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now