
-----------------------------------
rshah
Thu Jan 19, 2006 7:28 pm

make a calculator that adds and subtracts in binary numbers
-----------------------------------
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 (1, 1, 600, 400, white)
    cls

    %row number 1 of calculator (ON,1,4,7,+,Bin)

    drawfillbox (170, 150, 240, 210, brightred)
    locatexy (205, 180)
    color (white)
    put "1" ..

    drawfillbox (360, 150, 430, 210, brightblue)
    locatexy (395, 180)
    put "0" ..

    drawfillbox (170, 70, 240, 130, green)
    locatexy (205, 100)
    put "+" ..

    drawfillbox (360, 70, 430, 130, yellow)
    locatexy (405, 100)
    put "-" ..

    drawfillbox (270, -10, 340, 50, grey)
    locatexy (305, 20)
    put "Hex" ..

    drawfillbox (360, -10, 430, 50, purple)
    locatexy (395, 30)
    put "Dec" ..

    drawfillbox (270, 210, 340, 150, white)
    locatexy (305, 180)
    put "C" ..

    drawfillbox (170, -10, 240, 50, brightgreen)
    locatexy (205, 20)
    put "="

end calculatordesign

proc getValue (var A : array 1 .. 8 of int)
    var x, y, bnum, bud : int
    var count : int := 1

    for i : 1 .. 8
        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) := 0
            count := count + 1
        elsif x > 170 and x < 240 and y > 230 and y < 290 then
            A (count) := 1
            count := count + 1
        end if
        locatexy (1, maxy)
        for i : 1 .. count - 1
            put A (i) ..
        end for
        exit when count = 9
    end loop
end getValue

*************MAIN PROGRAM***************

var choice : int
var x, y, bnum, bud : int
var A : array 1 .. 8 of int
var font2 : int

optionmenu (choice, font2)


loop
    exit when choice = 2
    calculatordesign
    getValue (A)
end loop
loop
exit when hasch 
end loop

-----------------------------------
Drakain Zeil
Thu Jan 19, 2006 8:34 pm


-----------------------------------
I don't get it. What are you asking for?

-----------------------------------
rshah
Fri Jan 20, 2006 12:28 am

binary calculator - question
-----------------------------------
i am asking for how to allow the calculator to add and subtract in binary. The program should flow like this
1. user enters 1st binary number
2. user then enters operation
3. user then enters 2nd binary numbers
4. calculation is done

***also it would be helpful if you could help me with making the buttons of my calculation clickable and be able to view what i am clicking in a screen for the calculator***

-----------------------------------
Albrecd
Fri Jan 20, 2006 12:01 pm


-----------------------------------
First of all, you should create a regular calculator system that just uses "normal" numbers (easy), then you should create a method of converting binary into integers and back again (not as easy)
