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

Username:   Password: 
 RegisterRegister   
 how would I break a sentance into variables per word
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pozaj0206




PostPosted: Mon Dec 12, 2011 8:20 pm   Post subject: how would I break a sentance into variables per word

What is it you are trying to achieve?
I am trying to make a simple translator.


What is the problem you are having?
I don't know how I can have a whole sentence as input the have it split to variables word1, word2 ect.
IE.
I type "hello how are you"
and it makes
Engword1 = hello
Engword2 = how
Engword3 = are
Engword4 = you


Describe what you have tried to solve this problem
I have tried collecting each word at a time but I find its a bit inconvenient.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
here's a code snippet

Turing:


var Engword1 : string := ""
var Engword2 : string := ""
var Engword3 : string := ""
var Engword4 : string := ""
var Engword5 : string := ""

loop
put "Type the sentence that you wish to translate (max 10 words, no caps, no punctuation)"
get Engword1

if Engword1 = "hello"
then Dovword1 := "Bonjour"
cls



Please specify what version of Turing you are using
4.1
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Dec 12, 2011 8:24 pm   Post subject: RE:how would I break a sentance into variables per word

code:

get full_sentence : *
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
pozaj0206




PostPosted: Mon Dec 12, 2011 9:27 pm   Post subject: Re: RE:how would I break a sentance into variables per word

Tony @ Mon Dec 12, 2011 8:24 pm wrote:
code:

get full_sentence : *


ok, thanks tony but 1 question how exactly can I apply this to turing? like is full_sentence just a variable? and whats the : for?

thx
Tony




PostPosted: Mon Dec 12, 2011 9:32 pm   Post subject: RE:how would I break a sentance into variables per word

you can read up on the details in Turing's documentation -- get
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Velocity




PostPosted: Mon Dec 12, 2011 9:48 pm   Post subject: RE:how would I break a sentance into variables per word

the " :* " pretty much just allows the user to break the string and input a sentence with spaces into one line of code

Example :
CODE :
var full_name : string
put "What is your full name? " ..
get full_name : *
put full_name

Input : Roger bobby booshay kristoph

Output :Roger bobby booshay kristoph

but if you didnt have the " :* " it would be an error saying that you broke the string
Velocity




PostPosted: Mon Dec 12, 2011 9:50 pm   Post subject: RE:how would I break a sentance into variables per word

so like if you didnt have the " :* " it would say

Output :
Roger

because it only sees the first word that you entered.
pozaj0206




PostPosted: Tue Dec 13, 2011 3:33 pm   Post subject: Re: how would I break a sentance into variables per word

thx
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: