Page 1 of 1

binary calculator help - how to enable clicking

Posted: Fri Jan 20, 2006 10:04 am
by Anonymous
It would be appreciated if someone could help me with clicking on buttons, as well as where to place this code below in my turing program

var str1, str2 : string
var num1, num2 : int

get str1
get str2

num1 := strint (str1, 2)
num2 := strint (str2, 2)

put "The total is ", intstr (num1 + num2, 0, 2), "."

put "The total is ", intstr (num1 - num2, 0, 2), "."


****BINARY CALCULATOR****

var x, y, button : int
setscreen ("graphics:640;480")
proc optionmenu (var choice, font2 : int)

loop
colorback (blue)
cls
color (white)
font2 := Font.New ("Arial:19")
Font.Draw ("ADDING & SUBTRACTING BINARY CALCULATOR", 50, 400, font2, white)
Font.Draw ("Please enter your desired choice? Then type enter!", 50, 350, font2, white)
Font.Draw ("1. START", 50, 300, font2, white)
Font.Draw ("2. EXIT", 50, 250, font2, white)
locate (20, 40)
get choice
exit when choice = 1 or choice = 2
end loop

end optionmenu

proc calculatordesign

drawbox (120, 200, 190, 260, white)
cls
color (white)


drawfillbox (170, 250, 240, 310, brightred)
locatexy (205, 280)
put "1" ..

drawfillbox (360, 250, 430, 310, brightblue)
locatexy (395, 280)
put "0" ..

drawfillbox (170, 170, 240, 230, green)
locatexy (205, 200)
put "+" ..

drawfillbox (360, 170, 430, 230, yellow)
locatexy (395, 200)
put "-" ..

drawfillbox (270, 90, 340, 150, grey)
locatexy (295, 120)
put "Hex" ..

drawfillbox (360, 90, 430, 150, purple)
locatexy (395, 120)
put "=" ..

drawfillbox (270, 310, 340, 250, white)
locatexy (305, 280)
put "C" ..

drawfillbox (170, 90, 240, 150, brightgreen)
locatexy (195, 120)
put "Dec" ..

end calculatordesign

proc getValue (var A : array 1 .. 8 of int, var B : array 1..8 of int)

var x, y, bnum, bud : int
var count : int := 1

for i : 1 .. 1
A (i) := 0
end for


buttonwait ("down", x, y, bnum, bud)
loop
if x > 170 and x < 240 and y > 310 and y < 370 then
A (count) := 1
count := count + 1
elsif x > 170 and x < 240 and y > 230 and y < 290 then
for i : 1 .. 8
put A (i) ..
A (count) := 0
count := count - 1
end for

end if
locatexy (1, maxy)
for i : 1 .. count + 1
put A (i) ..
end for
locatexy (1, maxy)
buttonwait ("down", x, y, bnum, bud)
for c : 1 .. 8
put B © ..
B (count):= 1
count := count + 1
end for
exit when count = 9
end loop
end getValue

proc showanswer (var num1, num2 : int)

put "The total is ", intstr (num1 + num2, 0, 2), "."

put "The total is ", intstr (num1 - num2, 0, 2), "."

end showanswer

var choice : int
var x, y, bnum, bud : int
var A, B : real
var font2 : int
var num1, num2 : int
optionmenu (choice, font2)

loop
exit when choice = 2
end loop
calculatordesign
getValue (A, B)
showanswer (num1, num2)
loop
exit when hasch
end loop

**************HOW DO I GET IT TO WORK IVE BEEN TRYING FOR DAYS???

Archived topic from Iceteks, old topic ID:4120, old post ID:33690