Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to alphabeticize two inputted words when one of the words is capitalized?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
fruit7654321




PostPosted: Sun Jun 19, 2011 6:42 pm   Post subject: How to alphabeticize two inputted words when one of the words is capitalized?

What is it you are trying to achieve?
Hey guys. This is my first time at this forum and I'm still a newbie at Turing.
Anyways, the question I'm having trouble with is from my homework at school.

The exact questions is: "5. Write a program that asks for a word and then for a second word. The two words should then be printed in alphabetical order. Be sure to check that your program works correctly. "

If you're reading this, thanks for your time.


What is the problem you are having?
My problem, aforementioned in my title, is that the program works perfectly until the cases of the words are different.


Describe what you have tried to solve this problem
I've tried to fix this problem by first detecting a capitalized letter and changing it, but I don't know how to change it.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here's my code:

Turing:


var first, second : string

put "Enter the first word: " ..
get first

put "Enter the second word: " ..
get second

if (first < second) then
    put first, " ", second
else
    put second, " ", first
end if



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Sun Jun 19, 2011 6:56 pm   Post subject: RE:How to alphabeticize two inputted words when one of the words is capitalized?

That's because capital letters are different values than their lowercase brethren. Completely different sections of the chart actually:

Posted Image, might have been reduced in size. Click Image to view fullscreen.

Basically you want to either deal with just uppercase or lowercase for both strings.

Str.Lower
Str.Upper
fruit7654321




PostPosted: Sun Jun 19, 2011 7:01 pm   Post subject: Re: How to alphabeticize two inputted words when one of the words is capitalized?

Thanks for your reply. I understand it now Very Happy

Here's my new code, which works:

Turing:


var one, two:string
put "What is your first word? "..
get one
put "What is your second word? "..
get two

if Str.Lower(one)>two then
    put two, " ", one
elsif Str.Lower(two)>one then
    put one, " ", two
end if



Now my questions is: Is there a way to do this without using these keywords? And what if there were an undefined number of words to alphabetize? How would i do that?
Zren




PostPosted: Sun Jun 19, 2011 7:08 pm   Post subject: RE:How to alphabeticize two inputted words when one of the words is capitalized?

one = a
two = B

Broken.

As for your second question. You'd first have all the words in an array. Then you'd sort it.

There are tons of ways to sort, but focus on the Bubble sort as it's the easiest to learn (and a good stepping stone).
fruit7654321




PostPosted: Sun Jun 19, 2011 7:25 pm   Post subject: Re: How to alphabeticize two inputted words when one of the words is capitalized?

Okay, so i made it so that both strings would always be lowercase.

Thanks for your help.
RandomLetters




PostPosted: Sun Jun 19, 2011 9:51 pm   Post subject: RE:How to alphabeticize two inputted words when one of the words is capitalized?

Have you considered

one = a
two = a
fruit7654321




PostPosted: Mon Jun 20, 2011 5:53 pm   Post subject: Re: How to alphabeticize two inputted words when one of the words is capitalized?

Wouldn't making it >= and <= fix that?
RandomLetters




PostPosted: Mon Jun 20, 2011 5:55 pm   Post subject: RE:How to alphabeticize two inputted words when one of the words is capitalized?

Yes, but you don't need two if statements.
Sponsor
Sponsor
Sponsor
sponsor
fruit7654321




PostPosted: Mon Jun 20, 2011 5:59 pm   Post subject: Re: How to alphabeticize two inputted words when one of the words is capitalized?

Very Happy


code:

var one, two:string
put "What is your first word? "..
get one
put "What is your second word? "..
get two

if Str.Lower(one)>Str.Lower(two) then
    put two, " ", one
else
    put one, " ", two
end if
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: