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

Username:   Password: 
 RegisterRegister   
 Is it possible for a variable to be two or more types?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
qmanjr5




PostPosted: Tue Dec 01, 2009 8:59 pm   Post subject: Is it possible for a variable to be two or more types?

Such as
Turing:

var example1 : int : string


or whatever.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Dec 01, 2009 9:04 pm   Post subject: RE:Is it possible for a variable to be two or more types?

just to try to understand what it is you are actually looking for...

if I was to have such a variable, and it held a value of "qmanjr5", but I used it as an int, what int value would you expect to have?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
qmanjr5




PostPosted: Tue Dec 01, 2009 9:06 pm   Post subject: RE:Is it possible for a variable to be two or more types?

Erm, no idea? Very Happy

I have no idea what you mean.
An int is a number, not a string.
The reason I ask this is for my quiz I'm making. If I enter "lsmfpowe" for a question who's variable is an int, it screws up and won't continue. I realized this is because an int can't have letters (as far as I know?) so, I was wondering if I could make the variable be an integer and a string.

Or would I just put it as a string, since you can input numbers in a string?
Tony




PostPosted: Tue Dec 01, 2009 9:14 pm   Post subject: Re: RE:Is it possible for a variable to be two or more types?

qmanjr5 @ Tue Dec 01, 2009 9:06 pm wrote:
Erm, no idea? Very Happy

That's exactly why I ask Wink It's now clear that what you ask to have, is not what you actually want.

qmanjr5 @ Tue Dec 01, 2009 9:06 pm wrote:
Or would I just put it as a string, since you can input numbers in a string?
Indeed.

You might also be interested in strintok and strint functions.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
SNIPERDUDE




PostPosted: Tue Dec 01, 2009 9:22 pm   Post subject: RE:Is it possible for a variable to be two or more types?

Use strings for your answers. When you come across questions that require integers, Turing has built-n features such as strint (which converts a string to an integer), and strintok (which checks to see if a string can be converted to an integer, returning a boolean). Just look them up in the Turing documentation.

EDIT: Tony and your fast posting
Kharybdis




PostPosted: Tue Dec 01, 2009 9:31 pm   Post subject: RE:Is it possible for a variable to be two or more types?

A variable can't be an int and a string at the same time... that's just not possible.

I mean you can have the number 5 as a string.. but it would be declared as a string, not as an int.

You can interchange them if that's what you are seeking using the strintok, strreal, strint, and other functions.

EDIT: Wow, i'm such a slowpoke...
Tony




PostPosted: Tue Dec 01, 2009 9:38 pm   Post subject: Re: RE:Is it possible for a variable to be two or more types?

Kharybdis @ Tue Dec 01, 2009 9:31 pm wrote:
A variable can't be an int and a string at the same time... that's just not possible

It is!

It's called a Union. A variable is just a memory location that is holding some bits. Those bits could be interpreted as an integer, or as a string, or whatever else. In Turing, you can perform something similar via cheat
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
SNIPERDUDE




PostPosted: Wed Dec 02, 2009 11:54 am   Post subject: RE:Is it possible for a variable to be two or more types?

Well, that explains my query of was cheat is. Thanks Tony!
Sponsor
Sponsor
Sponsor
sponsor
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  [ 8 Posts ]
Jump to:   


Style:  
Search: