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

Username:   Password: 
 RegisterRegister   
 Hi i am having some problems
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shruti




PostPosted: Wed Apr 02, 2008 4:34 pm   Post subject: Hi i am having some problems

hi guys i am new. i have a question. i wrote this program where the output should be in alphabetical order but i am having some errors i dont know what it is. anotehr question is that if we have to replace every 4th cahracter in a word ...how to you do it ??? is there a formula or something ???????????

Quote:

var word:string
var word1 : string
var word2 : string
var word3 : string
put " please enter the first word ex, cappa "
get word1
put " please enter the second word ex, alpha"
get word2
put " please enter the third word ex, beta"
get word3
if (word1>word2) and (word1>word3) then
put "The words in alphabetical order "
elsif (word2<word1) or (word2>word3) then
put "The words in alphabetical order "
elsif ( word3<word1) or ( word3<word2) then
put " the words in alphabetical orders are ", word1, word2, word3
elsif (word1=word2) and (word1=word3)then
put " words are the same, smart !"
elsif ( word2=word1) and (word2=word3) then
put " words are the same, smart !"
elsif ( word3=word1) and (word3=word2) then
put " words are the same, smart!"
end if
put "The words in alphabetical order ", word1, word2, word3
get word1, word2, word3


i know that put "The words in alphabetical order ", word1, word2, word3" i shopuld not put word1..3 but i dont know what to do m

plzzzzzzzzzzzzzzz help me ASAP
thankyou Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Apr 02, 2008 4:55 pm   Post subject: RE:Hi i am having some problems

what kind of error are you having?

also... this makes little sense
code:

put "The words in alphabetical order ", word1, word2, word3
get word1, word2, word3
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
shruti




PostPosted: Wed Apr 02, 2008 5:02 pm   Post subject: RE:Hi i am having some problems

its not exactly an error but if i put some words that's not in alphabetical order. it outputs word1,2,3. in the order taht i put Sad
Tony




PostPosted: Wed Apr 02, 2008 5:33 pm   Post subject: RE:Hi i am having some problems

well you did say specifically that

put "The words in alphabetical order ", word1, word2, word3

what did you expect it to output there?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
shruti




PostPosted: Wed Apr 02, 2008 5:40 pm   Post subject: RE:Hi i am having some problems

i want the output to be that the words should be in alphbetical orderlike if you put ksr it will give what ever you put in but i want it in alphbetical order
The_Bean




PostPosted: Wed Apr 02, 2008 6:04 pm   Post subject: Re: Hi i am having some problems

To start off, it's best to use an array when your holding 3 of the same thing.
And it's also alot easier to manipulate later, and when you want to do it with 10 words.

The reason that it puts them back out in the same order is because that is what your having it do.
Turing:

if (word1>word2) and (word1>word3) then
put "The words in alphabetical order "  % this is all that it sais here, it doesn't say to output them at all in a different order.
elsif (word2<word1) or (word2>word3) then
put "The words in alphabetical order " % same here
elsif ( word3<word1) or ( word3<word2) then
put " the words in alphabetical orders are ", word1, word2, word3  % Now you have it outputting the words when the case= true, but its still 1,2,3
elsif (word1=word2) and (word1=word3)then
put " words are the same, smart !"
elsif ( word2=word1) and (word2=word3) then
put " words are the same, smart !"
elsif ( word3=word1) and (word3=word2) then
put " words are the same, smart!"
end if
put "The words in alphabetical order ", word1, word2, word3 % you are now outputting them in the same order and haven't changed the order in any way


Also get rid of the get word1, word2, word3 at the very end because it does nothing.

Now in order to properly sort the list a simple bubble sort will do. But in order to use the bubble sort you need the words in an array.
firstly declair your array, and the temporary variable you need for the bubble sort.
Turing:

var word := array 1..3 of string
var temp :string


now to call them use either a "for" statement or word(1),word(2)...
now that you have the words in its time to sort. Heres the bubble sort and how to use it
Turing:

for i:1..3 % the max of the array
   for ii:1..2 % the max of the array-1
      if word(ii)>word(ii+1) then  %so if the previous word is greater than the word after it then
         temp:=word(ii)
         word(ii):=word(ii+1) % these 3 things are switching word(ii) and word(ii+1) around
         word(ii+1):=temp
      end if
   end for
end for
put "The words in alphabetical order: "..
for i: 1..3
   put word(i)," "..
end for
put"" % stops the line continuation


Now theres probably a better method but to change the 4th letter you can do it like this
Turing:

for ii : 1 .. 3 % 1.. the number of words
    for i : 1 .. length (word (ii)) % 1 to the number of characters in the word
        if i = 4 then % if your on the 4th character
            put "k" .. % put the 4th character as k replace k with what ever you want
        else % if its not 4 then just put the letter that suppose ot be there
            put word (ii) (i) ..
        end if
    end for
    put ""
end for
shruti




PostPosted: Fri Apr 04, 2008 6:41 am   Post subject: RE:Hi i am having some problems

hey the Bean when i put the 1st command there is an errror i dont know why !
it says "syntax error at array"

an for the 2nd one there is also an error and it should be every 4th letter ! the error is " variale has no value " ...
plx help me
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  [ 7 Posts ]
Jump to:   


Style:  
Search: