Help with few assiments.
Author |
Message |
JR
|
Posted: Mon Feb 09, 2004 9:06 am Post subject: Help with few assiments. |
|
|
ok first one,
I need to write a program that reads a series of words and it has to output the middle letter of each word that has an odd number of letters or announce that the word has an even number of letters.
second:
write a program to read a series of worrds and output each word with letters in reserve sequence. so the word has to be in reserve when shown.
Thats all for now, thx. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Paul
|
Posted: Mon Feb 09, 2004 9:18 am Post subject: (No subject) |
|
|
The first one is easy, you can figure it out by yourself. just use the length function, find the length of the word, if the length div 2 = 1 then it has an odd number of letters. Then take the length and div 2 +1 to get the middle letter, which you can output by using:
code: |
word (length(word)+1)
|
The second one:
code: |
var ww : string
var wl: int := 0
put "Please enter the word: " ..
get ww
wl := length (ww)
put "Your word reversed is: " ..
for decreasing e : wl.. 1
put ww (e) ..
end for
|
This is also using the length function. Find the length of the word, run a for loop the number of times same as there are letters in the word, and output using the same output function as number one. |
|
|
|
|
|
JR
|
Posted: Mon Feb 09, 2004 9:29 am Post subject: (No subject) |
|
|
thx i got it to work, but i forgot osmething about number 2, lets say if i type a palindrome word like wow, or madam i need it to say that its a palindrome. |
|
|
|
|
|
JR
|
Posted: Mon Feb 09, 2004 9:55 am Post subject: (No subject) |
|
|
my program for #1 is screwy, something isnt right.
code: | var word1:string
var i:int
loop
put " type a word "
get word1
i:=length(word1)
if i div 2 = 1 then put " The middle letter is ",
word1(length(word1)+1)
end if
end loop
|
|
|
|
|
|
|
McKenzie
|
Posted: Mon Feb 09, 2004 11:21 am Post subject: (No subject) |
|
|
1. when you say you are trying to ask if it is odd right? Use
2. You need an else side for the even ones |
|
|
|
|
|
Paul
|
Posted: Mon Feb 09, 2004 1:33 pm Post subject: (No subject) |
|
|
The middle letter line:
code: |
word1(length(word1)+1)
|
is wrong I think...
instead it is
code: |
word1((length(word1))div 2+1)
|
|
|
|
|
|
|
netninja
|
Posted: Tue Feb 10, 2004 6:40 pm Post subject: (No subject) |
|
|
To add to this question, i would like to give each letter of the alphabet a value, for eg. a=1, b=2, c=3, d-4, in the easiest way possible, maybe without having to declare each var.
Maybe im wrong about making each letter have a value, but the following is what i want to do.
What i would like to do is make a program that takes words, and make each letter in those words go up or down one letter or more. For eg, cat = dbu , because i did cat+1 to each letter. I wish to make it so that I can do that with any set of letters, its more or less the start of an encryption program, but a simpler version for reference etc...
So is my idea of making the letters have values a good idea? If so, would using an array eg. 1..26 init (a,b,c,.... etc) is that the way to go about it? |
|
|
|
|
|
Paul
|
Posted: Tue Feb 10, 2004 6:52 pm Post subject: (No subject) |
|
|
Nah, you don't use an array, you use chr and ord. I'll dig up my old one somewhere and post it up in a sec.
Here it is:
code: |
var word : string
put "Enter a word: " ..
get word
put "Your encrypted word: " ..
for a : 1 .. length (word)
put chr (ord (word (a)) + 1) ..
end for
|
This is not fool proof, cause if it is, when the letter is z, it should go to a, but its just to give you an idea.
If you want it to go from z to a then this is how to do it, its not the simplest, but Im too lazy.
code: |
var word : string
put "Enter a word: " ..
get word
put "Your encrypted word: " ..
for a : 1 .. length (word)
if ord (word (a)) not= 90 and ord (word (a)) not= 122 then
put chr (ord (word (a)) + 1) ..
elsif ord (word (a)) not= 90 and ord (word (a)) = 122 then
put "a" ..
elsif ord (word (a)) not= 122 and ord (word (a)) = 90 then
put "A"
end if
end for
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Andy
|
Posted: Tue Feb 10, 2004 7:07 pm Post subject: (No subject) |
|
|
nxt time, be more sepcific in ur topic name... read the rulz of the site |
|
|
|
|
|
netninja
|
Posted: Wed Feb 11, 2004 9:42 am Post subject: (No subject) |
|
|
thank you Ill get to work on this. |
|
|
|
|
|
|
|