Computer Science Canada Lower case to upper case |
Author: | stef_ios [ Tue Apr 04, 2006 8:12 am ] |
Post subject: | Lower case to upper case |
Hey. I have to write a program that can get a name in lower case and then change the word and output it in all upper case letters. Here is the code I have so far, but I do not know how to write the most important part. I know I have to (in a loop) get the ASCII code of the letter (using ord), then subtract 32, and then output the number using it's chr equivalent. Can someone help me? Thanks so much. |
Author: | Andy [ Tue Apr 04, 2006 8:24 am ] |
Post subject: | |
sooo where is this code of yours? |
Author: | stef_ios [ Tue Apr 04, 2006 8:35 am ] |
Post subject: | |
oops. sorry. here is the start. var name: string var strlen: real put "Please enter your name in lower case letters: " get name loop end loop I am a noobie at this stuff. Anyways, I know I have to use ord, and chr, and strlen. I don't know how though. |
Author: | NikG [ Tue Apr 04, 2006 8:36 am ] |
Post subject: | |
Quote: I know I have to (in a loop) get the ASCII code of the letter (using ord), then subtract 32, and then output the number using it's chr equivalent.
That sound's about right. So what's the problem? Remember, if you're going to need this often then create a function. And don't forget to check whether the letter you are converting is indeed a lower case letter; otherwise you'll get a weird symbol. |
Author: | NikG [ Tue Apr 04, 2006 8:42 am ] | ||
Post subject: | |||
Oops, too slow with my first post. Anyways, think about what you need stef_ios. You're going to need to check each letter of whatever the user inputs. So yes you will need a loop, but is there a better choice than the normal loop? Here's a tip: if you have a string variable, you can access individual letters simply by putting a # in brackets.
|
Author: | Andy [ Tue Apr 04, 2006 8:58 am ] |
Post subject: | |
A few things the best tip i could give you is that you should create an seperate string to store the UpperCased letters. Instead of using a loop, use a for loop to go from 1 to length(name) in the body of the for loop, check to make sure if the current character is between 'a' and 'z' if it is, subtract 32 from the ord(character) then use chr to find the corresponding uppercase and attatch that to the end of your uppercased string if the character is between 'A' and 'Z' simply attatch it to the end of your uppercased string. what is the use of strlen? |
Author: | stef_ios [ Tue Apr 04, 2006 6:00 pm ] |
Post subject: | |
strlen is the variable used to find the length of the word, which is a string. |
Author: | person [ Tue Apr 04, 2006 6:20 pm ] |
Post subject: | |
y is it of type real? also, its not necessary at all |
Author: | chrispminis [ Tue Apr 04, 2006 11:30 pm ] |
Post subject: | |
Just a note, you may not be permitted to use it, but there is a Turing predefined function that does this. Can't recall atm, but you should be able to find it in the Turing help files. |
Author: | stef_ios [ Wed Apr 05, 2006 7:59 am ] |
Post subject: | |
can someone just start the code for me, so i can be on the right track, because i have absolutely no clue what i'm doing right now. Thanks. |
Author: | md [ Wed Apr 05, 2006 9:37 am ] | ||
Post subject: | |||
|
Author: | stef_ios [ Wed Apr 05, 2006 3:03 pm ] |
Post subject: | |
Could someone please help me. I actually have no clue how to do this, and it's an assignment. Could someone walk me through the steps (with examples), because i'm lost. I know what i have to do, i just don't know how to put it into turing. |
Author: | stef_ios [ Wed Apr 05, 2006 3:21 pm ] | ||
Post subject: | |||
Okay. So that is the code I came up with, but it doesn't work. Can someone check it over. Also, I need it to diplay the uppercase letter using the chr. Thanks. |
Author: | Delos [ Wed Apr 05, 2006 3:39 pm ] | ||||||
Post subject: | |||||||
ord() works only on a single character, and you'll need to pass it as a parameter:
Next:
And finally:
There you go, manipulation basics. From here you can figure out how to do the lower->UPPER conversions or vice versa. |
Author: | stef_ios [ Wed Apr 05, 2006 4:24 pm ] |
Post subject: | |
Thanks for all the tips. Greatly appreciated. |
Author: | Clayton [ Wed Apr 05, 2006 6:13 pm ] | ||||||||
Post subject: | |||||||||
stef_ios wrote:
Okay. So that is the code I came up with, but it doesn't work. Can someone check it over. Also, I need it to diplay the uppercase letter using the chr. Thanks. okay with your code there are a few problems: 1)y did you make 5 different variables, if you are only trying to change the case of one word or name 2)the syntax for a for loop looks like this
so what you are doing is making a for go from nothing, as it cannot read a string variable. 3)to use the ord() function properly you need to do the following:
so take the ord of the letter in brackets, or in your case it could look like this:
just make sure your variable is string type 4)also, when you get your word to change, you dont need to put five variables down, just the one, as you are just changing one word from what i understand well i hope that helps you out some, if you plan on getting a bit more serious with programming in turing i suggest you check out the Turing Walkthrough, it is a great help, and was created by some of the best here at compsci at turing |
Author: | stef_ios [ Sun Apr 09, 2006 3:03 pm ] | ||
Post subject: | |||
Hello again. So here is my code.
Now I need help with two more things. 1) How do I get the name printed onto one line? 2) How can I get it to recognize already capital letters and ignore them? Thanks!! |
Author: | MysticVegeta [ Sun Apr 09, 2006 7:14 pm ] | ||
Post subject: | |||
Hint for #1:
Hint for #2: Captals have ordinal vals 65 to (65+26) check if they are between them, if they are not then convert and output them otherwise just output them ![]() |
Author: | Clayton [ Sun Apr 09, 2006 7:52 pm ] |
Post subject: | |
what are the ord values for lowercase letters? |
Author: | [Gandalf] [ Sun Apr 09, 2006 9:46 pm ] |
Post subject: | |
Lower case letters are: 97 to 122 Upper case letters are: 65 to 90 In the future, make use of an ASCII chart. |
Author: | NikG [ Mon Apr 10, 2006 11:15 am ] |
Post subject: | |
Perhaps you should only look if the letter is lower case (i.e. ord value between 97 and 122) and convert if so, and otherwise just add the letter as it is. This way, you avoid weird characters because there is no conversion if the letter is capital, or it's something else like a symbol. |
Author: | stef_ios [ Mon Apr 10, 2006 6:47 pm ] | ||
Post subject: | |||
I know what needs to be done. I just don't know how to write the code. Here is what I tried, but it doesn't seem to work.
Could someone help me modify this code so it works. Thanks! |
Author: | HellblazerX [ Mon Apr 10, 2006 8:34 pm ] | ||
Post subject: | |||
try this:
|
Author: | stef_ios [ Tue Apr 11, 2006 7:50 am ] |
Post subject: | |
Thanks so much! Now i'm ll finished! Thanks to everyone who posted! The help was greatly appreciated! |