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

Username:   Password: 
 RegisterRegister   
 "get" help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
foo fighter




PostPosted: Wed Nov 23, 2005 11:48 am   Post subject: "get" help

how do i make a get command where the user doesn't have to press enter after typing in a word or number or somethin like that Confused [/b]
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Nov 23, 2005 11:51 am   Post subject: (No subject)

Turing:

var c : string (1)
getch (c)
put "you pressed : ", c

works for a single character. If you put getch() in a loop, you could get whole words
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
foo fighter




PostPosted: Wed Nov 23, 2005 12:18 pm   Post subject: (No subject)

alright well i understand how the strings work but it doesnt seem to work with int

this is what ive tried:

var number : int (1)
getch number[/b]
Tony




PostPosted: Wed Nov 23, 2005 12:20 pm   Post subject: (No subject)

it works for characters only.

if you want a digit, you getch() it as a character, and then strint() convert it to a digit
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
foo fighter




PostPosted: Wed Nov 23, 2005 12:32 pm   Post subject: (No subject)

could i get an example, cause i'm not familiar with strint commands
Tony




PostPosted: Wed Nov 23, 2005 12:35 pm   Post subject: (No subject)

Turing:
var c : string (1)
getch (c)
if strintok (c) then
    put strint (c), " is more than 5 :: ", strint (c) > 5
end if
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Albrecd




PostPosted: Wed Nov 23, 2005 1:19 pm   Post subject: (No subject)

code:

var stuff :char
put "please press a letter key"
stuff := getchar
put "you pressed the ",stuff," key"


Try that
foo fighter




PostPosted: Wed Nov 23, 2005 5:34 pm   Post subject: (No subject)

Ok im done with getch stuff. now i have a new problem, i cant divide integers

take at look:

var bi, binary : int

put "Enter a number: "
get bi

binary := bi / 2


when i divide by 2, i get "assigned value wrong type" 2 is high-lighted
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Wed Nov 23, 2005 6:37 pm   Post subject: (No subject)

That's because binary is an integer. But division using / returns a real number. (Think: 13 / 2).

Alternatives are to use div, as in
code:
binary := bi div 2

Or use round, as in
code:
binary := round (bi / 2)
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: