
-----------------------------------
drummaboy
Mon Dec 07, 2009 4:40 pm

How to count each number??? (sounds confusing? read more)
-----------------------------------
What is it you are trying to achieve?
I'm trying to make a binary to decimal caluculator and vice versa.

What is the problem you are having?
My teacher wants me to allow only 8 (eight) binary numbers and nothing more?
How can I make it so that it counts each number I put in?


Please specify what version of Turing you are using
4.1.1 Turing

-----------------------------------
qmanjr5
Mon Dec 07, 2009 4:41 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
[syntax="turing"]


Pointless reply, but I'm just letting you know :)

-----------------------------------
Tony
Mon Dec 07, 2009 4:47 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
you can use [tdoc]getch[/tdoc] to read 1 character at a time.

-----------------------------------
qmanjr5
Mon Dec 07, 2009 4:48 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
Yeah, listen to Tony, he's a genius :D

-----------------------------------
drummaboy
Mon Dec 07, 2009 6:40 pm

Re: How to count each number??? (sounds confusing? read more)
-----------------------------------
it doesn't make any sense to me. i read the link anfd I don't know how I could use it in my program.
and how can i set the max number of integers they're allowed to enter.

-----------------------------------
Tony
Mon Dec 07, 2009 6:42 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
what about it does not make sense? You ask getch for a character from a keyboard, and it sits around waiting until there is a character to read. Then it reads that character and gives it to you.

-----------------------------------
drummaboy
Mon Dec 07, 2009 6:46 pm

Re: How to count each number??? (sounds confusing? read more)
-----------------------------------
What I don't get is.

Binary is contained of 1's and 0's as u probably know.
So how do I make it so that it can detect 2 different keys?

-----------------------------------
Tony
Mon Dec 07, 2009 6:49 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
getch will detect any key.
[code]
var c : string (1)
put "press a key, any key..."
put "..."
put "Where is the \"any\" key?"
getch(c)
put ""
put c
[/code]

-----------------------------------
drummaboy
Mon Dec 07, 2009 6:55 pm

Re: How to count each number??? (sounds confusing? read more)
-----------------------------------
I know you might find this annoying, but will it detect it without me pressing enter?
and how do I set it to how much times a person can input a number thats wuh i really care about.
How many characters a person can type at once.

Ex: 1110 0111 and nothing more
I want to set it so that they can put up 2 eight characters and nothing more. 
But I kinda get what your saying about the key but I want to set it so that the key can only be pressed
a certain amount of times

-----------------------------------
Tony
Mon Dec 07, 2009 7:04 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
How about you just try it out and see how it works?

-----------------------------------
mirhagk
Mon Dec 07, 2009 7:09 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
just use it in a for loop
like:


var binary:=""
var c:string(1)
for i:1..8
getch(c)
binary+=c
end for


-----------------------------------
drummaboy
Mon Dec 07, 2009 7:14 pm

Re: How to count each number??? (sounds confusing? read more)
-----------------------------------
mirhagk thank you so much... thank you for not being rude about it.

ANd Tony I did try it and it kinda worked but not fully.
You got be patient with us newbies, we're not as skilled as you are and it doesn't help us
if you get so frustrated.

-----------------------------------
drummaboy
Mon Dec 07, 2009 7:21 pm

Re: How to count each number??? (sounds confusing? read more)
-----------------------------------
mirhagk I have one last question.... How can I make it so that they can't type anymore
what they reach the max amount.

Ex: I want them to be able 2 put in 8 characters.
How can I make it so that when they put in 8 characters, they can't type anymore and
therefore are forced to click enter.

-----------------------------------
Tony
Mon Dec 07, 2009 7:39 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
what happens when you enter more than 8 characters into mirhagk's code?

-----------------------------------
drummaboy
Mon Dec 07, 2009 10:17 pm

Re: How to count each number??? (sounds confusing? read more)
-----------------------------------
I can type more than 8 characters but when you click enter you get an error.
I want to make it so that they can't put more than 8 characters. so that they don't have to run the program over again.

-----------------------------------
Superskull85
Mon Dec 07, 2009 11:00 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
Are you sure you ran mirhagk's code on its own? I can only type eight characters using his/her code, nothing more.

-----------------------------------
qmanjr5
Mon Dec 07, 2009 11:24 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
Don't be rude to tony either, dude. He'll kill you :D

Just be patient with him, and he'll be patient with you

-----------------------------------
mirhagk
Mon Dec 07, 2009 11:30 pm

RE:How to count each number??? (sounds confusing? read more)
-----------------------------------
my code only works if you only want exaclty 8 characters (enter would be a 9)

the best way to do it would be to check the length and make sure each number is either a 1 or a 2.


var binary:string
var done:=false
loop
      get binary
      if length(binary)=8 then
done:=true
for i:1..8
if binary(i) not="1" and binary(i)not="2" then
done:=false
end if
end for
end if
exit when done
end loop

