Computer Science Canada Help with few assiments. |
Author: | JR [ 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. |
Author: | Paul [ Mon Feb 09, 2004 9:18 am ] | ||||
Post 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:
The second one:
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. |
Author: | JR [ Mon Feb 09, 2004 9:29 am ] |
Post 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. |
Author: | JR [ Mon Feb 09, 2004 9:55 am ] | ||
Post subject: | |||
my program for #1 is screwy, something isnt right.
|
Author: | McKenzie [ Mon Feb 09, 2004 11:21 am ] | ||||
Post subject: | |||||
1. when you say
2. You need an else side for the even ones |
Author: | Paul [ Mon Feb 09, 2004 1:33 pm ] | ||||
Post subject: | |||||
The middle letter line:
is wrong I think... instead it is
|
Author: | netninja [ Tue Feb 10, 2004 6:40 pm ] |
Post 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? |
Author: | Paul [ Tue Feb 10, 2004 6:52 pm ] | ||||
Post 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:
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.
|
Author: | Andy [ Tue Feb 10, 2004 7:07 pm ] |
Post subject: | |
nxt time, be more sepcific in ur topic name... read the rulz of the site |
Author: | netninja [ Wed Feb 11, 2004 9:42 am ] |
Post subject: | |
thank you Ill get to work on this. |