?
Solved

Help with control and strings

Posted on 2003-03-25
4
Medium Priority
?
163 Views
Last Modified: 2010-04-16
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
Comment
Question by:sajidaziz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Accepted Solution

by:
lmikle earned 200 total points
ID: 8205635
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 8207250
Good homework exercise!!!

mlmcc
0
 
LVL 15

Expert Comment

by:VGR
ID: 8208993
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
 

Author Comment

by:sajidaziz
ID: 8212879
Thankyou for your help
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question