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

Username:   Password: 
 RegisterRegister   
 Put and get on the same line...
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aldreneo




PostPosted: Tue May 02, 2006 6:45 pm   Post subject: Put and get on the same line...

How can I make it do this
code:

var age:string
put "How old are you" + get age

So that they are outputted on the same line?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue May 02, 2006 6:51 pm   Post subject: (No subject)

Judging by the title, I got excited and thought someone was asking how to use "get" as a function, rather than a cruddy keyword, so you can do things like
code:
put get

or
code:
name = get


Well, to answer your question, you need to add a .. after the put line:
code:
var age : string
put "How old are you? " ..
get age
TokenHerbz




PostPosted: Tue May 02, 2006 6:58 pm   Post subject: (No subject)

aha, unless me means to use the put and get on the same line in the CODE

which i dont do but...

code:

put "Get text: " .. get text
TokenHerbz




PostPosted: Tue May 02, 2006 7:03 pm   Post subject: (No subject)

you can make lines of code on a line, but i dont reccomend doing this at all, because its sloppy, and confusing:

Bad way:
code:

var text: string put "Get text: " .. get text put text

Better way:
code:

var text: string

put "get text:" ..    %%these two ..'s allow the line to be joined by other things
get text

put text


ex: of joining output to make it one line on screen, like cervantes said..

code:

put "Part 1 " ..
put "Part 2 " ..
put "Part 3"
Clayton




PostPosted: Tue May 02, 2006 8:43 pm   Post subject: (No subject)

out of curiosity Cervantes, what do you mean using get as a function, i didnt think that was possible....
do_pete




PostPosted: Tue May 02, 2006 8:56 pm   Post subject: (No subject)

It's not possible.
[Gandalf]




PostPosted: Tue May 02, 2006 9:09 pm   Post subject: (No subject)

do_pete wrote:
It's not possible.

Why not?
code:
fcn get_s : string
    var str : string
    get str :*
    result str
end get_s

put get_s
Clayton




PostPosted: Tue May 02, 2006 9:33 pm   Post subject: (No subject)

but why would you do that, i mean, what is the purpose of such a fcn?
Sponsor
Sponsor
Sponsor
sponsor
do_pete




PostPosted: Tue May 02, 2006 9:45 pm   Post subject: (No subject)

[Gandalf] wrote:
do_pete wrote:
It's not possible.

Why not?
code:
fcn get_s : string
    var str : string
    get str :*
    result str
end get_s

put get_s
No, I meant get can't be used like this:
code:
a := get
[Gandalf]




PostPosted: Tue May 02, 2006 10:37 pm   Post subject: (No subject)

do_pete wrote:
No, I meant get can't be used like this:
code:
a := get

code:
fcn get_s : string
    var str : string
    get str :*
    result str
end get_s

var a : string
a := get_s

Confused
do_pete




PostPosted: Tue May 02, 2006 10:42 pm   Post subject: (No subject)

No I mean the get you use in this:
code:
get a
cannot be used like this:
code:
a := get
[Gandalf]




PostPosted: Tue May 02, 2006 10:48 pm   Post subject: (No subject)

Ah, I see. Well, yeah, that's because get is created that way internally. That doesn't stop you from simulating a get() function, as I believe Cervantes was trying to say.
upthescale




PostPosted: Wed May 03, 2006 5:11 pm   Post subject: (No subject)

locate is an option to...


put"What is your name?"

locate(1,20)
get name
do_pete




PostPosted: Wed May 03, 2006 5:26 pm   Post subject: (No subject)

Or you could just do it Cervantes' way since it's much easier.
Cervantes




PostPosted: Sat May 06, 2006 1:03 pm   Post subject: (No subject)

Gandalf's got it. That's what I was geting at

do_pete, you're not seeing the power of using a gets type call as a function.

Say I was doing Martin's Roman_Numeral challege. I made a function to determine if a given string is a valid roman numeral.
code:

function is_valid_roman_numeral (s : string) : boolean
    % Compute!
end is_valid_roman_numeral

Now, how would I call it? Using get as a keyword, I have no choice but to use a temporary variable that really doesn't serve any purpose whatsoever:
code:

var temp : string
get temp
put is_valid_roman_numeral (temp)

However, if I use a get as a function (like Gandalf has done), then I don't have to create a useless variable, and I can shrink the program call to one line:
code:

put is_valid_roman_numeral (get)

Much nicer, yes?
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 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: