Author |
Message |
drummaboy
|
Posted: Mon Dec 07, 2009 4:40 pm Post subject: 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?
[/syntax]
<% procedure for the main menu
procedure mainmenu
colorback (black)
drawfillbox (0,0,maxx,maxy,black)
var fnt : int
fnt := Font.New ("Harrington:25")
Draw.Text ("Calculator program", 150,maxy div 2, fnt, brightred)
locate (15, 20)
Text.Color (75)
put "Press 1 - For Conversion from Decimal to Binary"
locate (18,20)
Text.Color (25)
put "Press 2 - For Conversion from Binary to Decimal"
locate (21,20)
Text.Color (5)
put "Press 3 - To exit"
end mainmenu
% end of procedure main menu
% start of the actual calculator
procedure calculator
locate (24,20)
var num : int
var calculator : int
var calspr : int
get num
calculator := Pic.FileNew ("calculate.bmp")
if num = 1 then
locate (24,20)
Text.Color (75)
put "You have chosen Decimal to binary"
elsif num = 2 then
locate (24,20)
Text.Color (25)
put "You have chosen Binary to Decimal"
delay (1500)
drawfillbox (0,0,maxx,maxy,yellow)
colorback (yellow)
Pic.Draw (calculator, 150,-100, picCopy)
loop
locate (1,20)
colorback (white)
put "Enter a Binary number (between 1-8)"
var binary : nat
locate (5,35)
get binary
cls
drawfillbox (0,0,maxx,maxy,yellow)
colorback (yellow)
Pic.Draw (calculator, 150,-100, picCopy)
if binary < 0 or binary > 1 then
put "put in a real binary number"
end if
end loop
elsif num = 3 then
locate (24,20)
Text.Color (5)
put "You have chosen to exit"
quit
end if
end calculator
mainmenu
calculator
>
[/syntax]
Please specify what version of Turing you are using
4.1.1 Turing |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
qmanjr5
|
Posted: Mon Dec 07, 2009 4:41 pm Post subject: RE:How to count each number??? (sounds confusing? read more) |
|
|
[syntax="turing"]
Pointless reply, but I'm just letting you know  |
|
|
|
|
 |
Tony

|
Posted: Mon Dec 07, 2009 4:47 pm Post subject: RE:How to count each number??? (sounds confusing? read more) |
|
|
you can use getch to read 1 character at a time. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
qmanjr5
|
Posted: Mon Dec 07, 2009 4:48 pm Post subject: RE:How to count each number??? (sounds confusing? read more) |
|
|
Yeah, listen to Tony, he's a genius  |
|
|
|
|
 |
drummaboy
|
Posted: Mon Dec 07, 2009 6:40 pm Post subject: 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

|
Posted: Mon Dec 07, 2009 6:42 pm Post subject: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
drummaboy
|
Posted: Mon Dec 07, 2009 6:46 pm Post subject: 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

|
Posted: Mon Dec 07, 2009 6:49 pm Post subject: 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
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Sponsor Sponsor

|
|
 |
drummaboy
|
Posted: Mon Dec 07, 2009 6:55 pm Post subject: 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

|
Posted: Mon Dec 07, 2009 7:04 pm Post subject: RE:How to count each number??? (sounds confusing? read more) |
|
|
How about you just try it out and see how it works? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
mirhagk
|
Posted: Mon Dec 07, 2009 7:09 pm Post subject: RE:How to count each number??? (sounds confusing? read more) |
|
|
just use it in a for loop
like:
Turing: |
var binary: =""
var c: string(1)
for i: 1.. 8
getch(c )
binary+=c
end for
|
|
|
|
|
|
 |
drummaboy
|
Posted: Mon Dec 07, 2009 7:14 pm Post subject: 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
|
Posted: Mon Dec 07, 2009 7:21 pm Post subject: 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

|
Posted: Mon Dec 07, 2009 7:39 pm Post subject: RE:How to count each number??? (sounds confusing? read more) |
|
|
what happens when you enter more than 8 characters into mirhagk's code? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
drummaboy
|
Posted: Mon Dec 07, 2009 10:17 pm Post subject: 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. |
|
|
|
|
 |
|