Author |
Message |
foo fighter
|
Posted: 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 [/b] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
foo fighter
|
Posted: 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
|
Posted: 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
foo fighter
|
Posted: 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
|
|
|
|
|
Albrecd
|
Posted: 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
|
Posted: 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
|
|
|
Cervantes
|
Posted: 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
Or use round, as in
code: | binary := round (bi / 2) |
|
|
|
|
|
|
|