Out putting getting the middle letter of a string
Author |
Message |
daneck13
|
Posted: Mon Feb 21, 2011 11:25 am Post subject: Out putting getting the middle letter of a string |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
What is the problem you are having?
<Answer Here>
Describe what you have tried to solve this problem
<Answer Here>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
andrew.
|
Posted: Mon Feb 21, 2011 11:26 am Post subject: RE:Out putting getting the middle letter of a string |
|
|
A couple of hints:
- what constitutes whether a number is odd or even (think modulo)? You shouldn't have if 1,2,4,6,8, etc.
- to find the middle letter in a phrase, divide the length by 2 and then round up (i.e. use the ceil function) |
|
|
|
|
 |
daneck13
|
Posted: Mon Feb 21, 2011 11:29 am Post subject: RE:Out putting getting the middle letter of a string |
|
|
thanks sorry got confused with the help thing i have some thing all ready it just dosent work
put "this program will tell u if a word has an odd or even # of letters , if odd the the program will tell u what the middle letter is"
put "Enter your word"
var word: string
var output : string
var letter : string
loop
get word
var outpt : real:= (length (word))
put "The word is ", outpt ..
put" letters long."
%odd or even
if outpt=1,2,4,6,8
then
put"cant find middle letter because there is a even number of letters"
else
var x : real:= outpt /2
put x
% now using the x find the middle letter
end if
end loop |
|
|
|
|
 |
RandomLetters
|
Posted: Mon Feb 21, 2011 2:03 pm Post subject: RE:Out putting getting the middle letter of a string |
|
|
Also, 1 is not an even number. |
|
|
|
|
 |
Raknarg

|
Posted: Wed Feb 23, 2011 11:19 am Post subject: RE:Out putting getting the middle letter of a string |
|
|
K, if your trying to find a specific peice of string, there's a little thing called "length". It'll tell you the length of the string.
So for instance, you were trying to find the middle letter of the word "seven"...
length ("seven") div 2
that gives the position of the letter halfway in. However, if you want to put that letter to the screen...
put word (length ("seven") div 2)
that will output the letter in postion 2.
its a little vague, so ask again if you need me to clear that up. |
|
|
|
|
 |
Insectoid

|
Posted: Wed Feb 23, 2011 11:32 am Post subject: RE:Out putting getting the middle letter of a string |
|
|
@Raknarg- if you'd read OP's code you'd see he already uses length().
@OP, any number modulo 2 will tell you if that number is odd or ever, ie
5%2 = 1 //5 is odd
6%2 = 0 //6 is even
As you can see, if n mod 2 = 1, n is odd. If n mod 2 = 0, n is even. Use this to your advantage.
Once you know if the number is odd or even, you can use div to find the middle character. |
|
|
|
|
 |
|
|