Detecting Keywords
Author |
Message |
PJ_69
|
Posted: Mon Feb 27, 2006 1:44 pm Post subject: Detecting Keywords |
|
|
Hey guys, i wrote a program that detects if the world "use" exists in given input
code: | % 4. Write a program that asks the user to enter a word or phrase.
% Check to see if the user's input contains the word "use". Then
% a message will appear that tells the user that:
%
% a) whether or not the word "use" is found.
% b) if it is found, where it begins.
%
% Example :
% the user's input is "homework is helpful" Ouput : Not found
% the user's input is "alcohol abuse is unhealthy" Output : Found, starting at 11
%
% This program was created by: Peter Jozwik.
%Variables
var wordphrase : string
var wordlength, count : int
% Gets the phrase or word
put "Please type in any phrase, or any word"
get wordphrase : *
wordlength := length (wordphrase)
put ""
%Checks if the word "use" is located within the word or phrase
count := 0
for a : 1 .. wordlength - 2
if wordphrase (a .. a + 2) = "use"
then
put "Found, starting at line ", a
else
count := count
end if
if wordphrase (a .. a + 2) = "use"
then
count := count + 1
end if
end for
%One of the ending outputs ("Found" or "Not Found")
if count = 0
then
put "not found"
elsif count = 1 then
put "The word use has been used 1 time on line "
elsif count > 1 then
put "The word use has been used ", count, " times"
end if
|
Please dont copy this straight.. at least learn how to write this yourself if you're going to use it. Thank you |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Andy
|
Posted: Mon Feb 27, 2006 1:54 pm Post subject: (No subject) |
|
|
Thanks.. next time please dont be such a dick and type in caps/ call people noobs |
|
|
|
|
|
cool dude
|
Posted: Mon Feb 27, 2006 5:47 pm Post subject: (No subject) |
|
|
Andy wrote: Thanks.. next time please dont be such a **** and type in caps/ call people noobs
sorry did i miss something?
anyhow u should error proof your program a little more. i.e. if i spell "Use" with a cappital letter it will say not found. also u shouldn't say line watever because its on the same line. just state which space its located.
P.S. i highly doubt anyone will copy your code and u don't have to say that and if your so worried don't post it. besides theres no need to copy a program like that we could make it in less than 20 min |
|
|
|
|
|
Andy
|
Posted: Mon Feb 27, 2006 5:51 pm Post subject: (No subject) |
|
|
yea you did miss something |
|
|
|
|
|
MysticVegeta
|
Posted: Thu Mar 02, 2006 6:33 pm Post subject: (No subject) |
|
|
Why go through loops?
Same code in 7 lines...
code: | var s : string
get s
if index (s, "use") > 0 then
put "Found at ", index (s, "use")
else
put "Not found"
end if
|
|
|
|
|
|
|
Booya
|
Posted: Sun Mar 05, 2006 7:07 pm Post subject: Program |
|
|
Nice Program! |
|
|
|
|
|
[Gandalf]
|
Posted: Sun Mar 05, 2006 7:27 pm Post subject: (No subject) |
|
|
Guess he didn't know index()...
Booya, why don't you start posting useful things? As much as praise is appreciated, you should have some other valuable input in your post. Best of all, you should read the forum rules. |
|
|
|
|
|
Booya
|
Posted: Sun Mar 05, 2006 7:35 pm Post subject: Posting |
|
|
Oh ok! Makes sence! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|