
-----------------------------------
huskiesgoaler34
Sat Jan 15, 2011 8:44 pm

Urgent Help for Calculator Program
-----------------------------------
What is it you are trying to achieve?

Being able to answer the equation

What is the problem you are having?
can't calculate the answer


Describe what you have tried to solve this problem

I wrote the code but it doesn't work

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

View.Set ("graphics:602;662,nobuttonbar,title: KoolCulator") %sets screen graphics to specific dimensions (title is set, toolbar is removed)
colourback (black) %sets screen background colour to black
cls                %allows whole screen colour to be set to black

%Main Program for my Calculator

colour (white)    %sets font to white (Only used this for seeing outputted answer while testing my program)

%Global Variables

var xcoordinate : int       %the x coordinate of the button (used for determining if the button has been pressed)
var ycoordinate : int       %the y coordinate of the button (used for determining if the button has been pressed)
var button : int            %the value of the button (used for determining if the mouse has been clicked; set to 0 if no click, 1 if there is a click)
var buttoncheck : boolean   %checks to see if the button has been clicked, if it has been, then if statements are activated
buttoncheck := false        %set to false (button hasn't been pressed); value is either true or false (button has been pressed or hasn't been pressed)
var buttonfont : int        %the declaration of the font used for the number and operation buttons
var offbuttonfont : int     %the declaration of the font used for the off button
var clearbuttonfont : int   %the declaration of the font used for the clear button
var number1 : string := ""
var number2 : string := ""
var operation : string := ""
var answer : int := 0


%Draws the button that the numbers will be outputed to

Draw.FillBox (10, 520, 590, 650, grey)     %draws the area where the numbers are outputed onto the screen

%Draws the first column of buttons for calculator

Draw.FillBox (10, 10, 350, 110, white)     %draws the 0 button onto the screen
Draw.FillBox (10, 130, 110, 240, white)     %draws the 1 button onto the screen
Draw.FillBox (10, 260, 110, 370, white)     %draws the 4 button onto the screen
Draw.FillBox (10, 390, 110, 500, white)     %draws the 7 button onto the screen

%Draws the second column of buttons for calculator

Draw.FillBox (130, 130, 230, 240, white)     %draws the 2 button onto the screen
Draw.FillBox (130, 260, 230, 370, white)     %draws the 5 button onto the screen
Draw.FillBox (130, 390, 230, 500, white)     %draws the 8 button onto the screen

%Draws the third column of buttons for calculator

Draw.FillBox (250, 130, 350, 240, white)     %draws the 3 button onto the screen
Draw.FillBox (250, 260, 350, 370, white)     %draws the 6 button onto the screen
Draw.FillBox (250, 390, 350, 500, white)     %draws the 9 button onto the screen

%Draws the fourth column of buttons for calculator

Draw.FillBox (370, 10, 470, 110, white)     %draws the decimal button onto the screen
Draw.FillBox (370, 130, 470, 240, white)     %draws the addition button onto the screen
Draw.FillBox (370, 260, 470, 370, white)     %draws the  multiplication button onto the screen
Draw.FillBox (370, 390, 470, 500, red)     %draws the delete button onto the screen

%Draws the fifth column of buttons for calculator

Draw.FillBox (490, 10, 590, 110, white)     %draws the equal button onto the screen
Draw.FillBox (490, 130, 590, 240, white)     %draws the subtraction button onto the screen
Draw.FillBox (490, 260, 590, 370, white)     %draws the division onto the screen
Draw.FillBox (490, 390, 590, 500, red)     %draws the off button onto the screen

buttonfont := Font.New ("TimesNewRoman:56")            %declares the value of buttonfont (Times New Roman font with a size of 56)
offbuttonfont := Font.New ("TimesNewRoman:36:bold")     %declares the value of buttonfont (Times New Roman font, bolded with a size of 36)
clearbuttonfont := Font.New ("TimesNewRoman:32:bold")     %declares the value of buttonfont (Times New Roman font, bolded with a size of 36)

Font.Draw ("0", 165, 35, buttonfont, black)     %draws the 0 onto the 0 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("1", 40, 155, buttonfont, black)     %draws the 1 onto the 1 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("2", 160, 155, buttonfont, black)     %draws the 2 onto the 2 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("3", 280, 155, buttonfont, black)     %draws the 3 onto the 3 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("4", 40, 290, buttonfont, black)     %draws the 4 onto the 4 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("5", 160, 290, buttonfont, black)     %draws the 5 onto the 5 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("6", 280, 290, buttonfont, black)     %draws the 6 onto the 6 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("7", 40, 420, buttonfont, black)     %draws the 7 onto the 7 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("8", 160, 420, buttonfont, black)     %draws the 8 onto the 8 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("9", 280, 420, buttonfont, black)     %draws the 9 onto the 9 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw (".", 408, 53, buttonfont, black)     %draws the . onto the decimal button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("+", 398, 155, buttonfont, black)     %draws the + onto the addition button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("-", 527, 160, buttonfont, black)     %draws the - onto the subtraction button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("x", 402, 290, buttonfont, black)     %draws the x onto the multiplication button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("?", 520, 283, buttonfont, black)     %draws the ? onto the division button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("=", 517, 34, buttonfont, black)     %draws the = onto the equal button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("OFF", 494, 425, offbuttonfont, white)     %draws the OFF onto the off button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("DEL", 377, 425, clearbuttonfont, white)     %draws the DEL onto the delete button for the calculator at these coordinates, using black font, using buttonfont
Font.Free (offbuttonfont)                            %used to free the memory used by the font that won't be needed for the rest of the program

loop        % 10 and ycoordinate < 110 then       %if the mouse was clicked in this area then...
                    number1 := number1 + "0"     %...add 0 to the value of number1
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "1"     %...add 1 to the value of number1
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "2"     %...add 2 to the value of number1
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "3"     %...add 3 to the value of number1
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 260 and ycoordinate < 370 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "4"     %...add 4 to the value of number1
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 260 and ycoordinate < 370 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "5"     %...add 5 to the value of number1
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 260 and ycoordinate < 370 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "6"     %...add 6 to the value of number1
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 390 and ycoordinate < 500 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "7"     %...add 7 to the value of number1
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 390 and ycoordinate < 500 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "8"     %...add 8 to the value of number1
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 390 and ycoordinate < 500 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "9"     %...add 9 to the value of number1
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 10 and ycoordinate < 110 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "."     %...add . to the value of number1
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 390 and ycoordinate < 500 then     %if the mouse was clicked in this area then...
                    number1 := ""     %...clears the numbers off the screen
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    operation := "+"
                    exit
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 260 and ycoordinate < 370 then     %if the mouse was clicked in this area then...
                    operation := "x"
                    exit
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    operation := "-"
                    exit

                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 260 and ycoordinate < 370 then
                    operation := "?"
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 10 and ycoordinate < 110 then

                end if
            end if

            exit when xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 390 and ycoordinate < 500

        else
            if button = 0 then
                buttoncheck := false
            end if
        end if

        Font.Draw (number1, 100, 530, buttonfont, black)     %draws inputed answer

        Draw.FillBox (10, 520, 590, 650, grey)

    end loop     % 10 and ycoordinate < 110 then         %if the mouse was clicked in this area then...
                    number2 := number2 + "0"     %...add 0 to the value of number2
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "1"     %...add 1 to the value of number2
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "2"     %...add 2 to the value of number2
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "3"     %...add 3 to the value of number2
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 260 and ycoordinate < 370 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "4"     %...add 4 to the value of number2
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 260 and ycoordinate < 370 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "5"     %...add 5 to the value of number2
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 260 and ycoordinate < 370 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "6"     %...add 6 to the value of number2
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 390 and ycoordinate < 500 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "7"     %...add 7 to the value of number2
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 390 and ycoordinate < 500 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "8"     %...add 8 to the value of number2
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 390 and ycoordinate < 500 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "9"     %...add 9 to the value of number2
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 10 and ycoordinate < 110 then
                    number2 := number2 + "."     %...add . to the value of number2
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 390 and ycoordinate < 500 then
                    number2 := ""
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 130 and ycoordinate < 240 then
                    operation := "+"
                    exit
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 260 and ycoordinate < 370 then
                    operation := "x"
                    exit
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 130 and ycoordinate < 240 then
                    operation := "-"
                    exit
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 260 and ycoordinate < 370 then
                    operation := "?"
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 10 and ycoordinate < 110 then
                    exit
                end if
                %exit when xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 390 and ycoordinate < 500

            end if

        else
            if button = 0 then
                buttoncheck := false
            end if
        end if

        Font.Draw (number2, 100, 530, buttonfont, black)     %draws inputed answer

        Draw.FillBox (10, 520, 590, 650, grey)

    end loop

    
        if operation = "x" then
            answer := strint (number1) * strint (number2)
        elsif operation = "?" then
            answer := strint (number1) div strint (number2)
        elsif operation = "+" then
            answer := strint (number1) + strint (number2)
        elsif operation = "-" then
            answer := strint (number1) - strint (number2)
        end if

    


    
    Draw.FillBox (10, 520, 590, 650, grey)

    Font.Draw (intstr (answer), 100, 530, buttonfont, black)


    
    
end loop

%End of Program

Please specify what version of Turing you are using

4.1.1

-----------------------------------
huskiesgoaler34
Sat Jan 15, 2011 9:05 pm

Re: Urgent Help for Calculator Program
-----------------------------------
HELP PLEASE!

-----------------------------------
Tony
Sat Jan 15, 2011 9:25 pm

RE:Urgent Help for Calculator Program
-----------------------------------

...but it doesn't work...

In what way does it not work...

-----------------------------------
huskiesgoaler34
Sat Jan 15, 2011 9:43 pm

Re: Urgent Help for Calculator Program
-----------------------------------
the answer is not calculated and is not put to the screen. My goal is to create a function to store the calculations and then call the function when one of the variables are pressed.

-----------------------------------
Tony
Sat Jan 15, 2011 9:48 pm

RE:Urgent Help for Calculator Program
-----------------------------------
That is too generic. The answer might not be calculated for any number of reasons.

-----------------------------------
huskiesgoaler34
Sat Jan 15, 2011 9:58 pm

Re: Urgent Help for Calculator Program
-----------------------------------
for example : If I press 5 +3, the answer is 5
another problem is that when i go cls (delete button) and i add 9 +1, the answer is 91.

-----------------------------------
Tony
Sat Jan 15, 2011 10:05 pm

RE:Urgent Help for Calculator Program
-----------------------------------
Perhaps you should check what the values of number1 and number2 actually at, at the moment when you are calculating your "answer". See if they are what you expect them to be.

-----------------------------------
huskiesgoaler34
Sat Jan 15, 2011 10:57 pm

Re: Urgent Help for Calculator Program
-----------------------------------
I did and I really don't see a problem. If a number button is pressed, then the value is added to either number1 or number2, depending if an operation has been selected before that. I add that value because if I press the 7, 6,and 1 buttons, Turing would see this as 7, 6, and 1, not 761. By doing this, the value is 761. I want this value to be stored when an operation is pressed for future calculations. Do you have any suggestions on why the variable values are not what they are supposed to be. When I test my calculator out, the values of number1 and number2 come up instead of the answer itself most of the time.

I wish Turing has a built-in BEDMAS function.

-----------------------------------
huskiesgoaler34
Sat Jan 15, 2011 11:00 pm

Re: Urgent Help for Calculator Program
-----------------------------------
I just noticed that when you continually use the calculator, the answer always comes out to be the last entered number. Where should I set the variables back at 0. I thought the end of the program but they don't work there.

-----------------------------------
Tony
Sat Jan 15, 2011 11:44 pm

Re: Urgent Help for Calculator Program
-----------------------------------
Do you have any suggestions on why the variable values are not what they are supposed to be.
If you know what the values actually are, instead of what you think they should be, that should give a hint as to where things might have gone wrong.

BEDMAS stuff -- you could always implement a Reverse Polish notation based calculator -- http://en.wikipedia.org/wiki/Reverse_Polish_notation

During the 1970s and 1980s, RPN had some currency even among the general public, as it was widely used in handheld calculators of the time ? for example, the HP-10C series and Sinclair Scientific calculators.


-----------------------------------
huskiesgoaler34
Sun Jan 16, 2011 8:41 am

Re: Urgent Help for Calculator Program
-----------------------------------
Can you please help me try to find out what the variables actually are? Can you tell me which line so I can figure it out and try to fix it? I understand what RVN does but have no clue how to add it into the program.

-----------------------------------
Tony
Sun Jan 16, 2011 9:24 am

Re: RE:Urgent Help for Calculator Program
-----------------------------------
Perhaps you should check what the values of number1 and number2 actually at, at the moment when you are calculating your "answer".
Such as with a put statement. Unique put statements tell you both where the code is executing and what the (select) values are at that moment.

-----------------------------------
huskiesgoaler34
Sun Jan 16, 2011 10:39 am

Re: Urgent Help for Calculator Program
-----------------------------------
I did it Tony, thanks a lot. I created put statements at the beginning of the calculations to check the values and then a put statement after the calculation to put the answer on the screen. One problem though. When I try to use Font.Draw, the answer is not drawn. I have included my code. Can you please give me an idea. By the way, thanks so much for helping. I really appreciated that you helped me without giving away the answer. Thanks! :D  :D 

 put number1
    put number2

    if operation = "*" then
        answer := strint (number1) * strint (number2)
        put answer
    elsif operation = "/" then
        answer := strint (number1) div strint (number2)
        put answer
    elsif operation = "+" then
        answer := strint (number1) + strint (number2)
        put answer
    elsif operation = "-" then
        answer := strint (number1) - strint (number2)
        put answer
       

    end if



    Font.Draw (intstr (answer), 100, 530, buttonfont, black) %this is where i want to put the answer to the screen using that text but it doesn't do it

    Draw.FillBox (10, 520, 590, 650, grey)

-----------------------------------
huskiesgoaler34
Sun Jan 16, 2011 11:37 am

Re: Urgent Help for Calculator Program
-----------------------------------
Even when I try to convert it to a string (from an int using intstr) it doesn't work

-----------------------------------
TokenHerbz
Sun Jan 16, 2011 11:43 am

RE:Urgent Help for Calculator Program
-----------------------------------
do you get errors, your font.draw looks correct.

answer is an int form? and your numbers in calc are strings?

Perhaps its located in the wrong spot in your loop, could you post more code?

-----------------------------------
huskiesgoaler34
Sun Jan 16, 2011 12:10 pm

Re: Urgent Help for Calculator Program
-----------------------------------
no errors, here is the rest of the code. it works well actually but I just want it draw the answer for me.

sorry for the immense commenting, it's required.


View.Set ("graphics:602;662,nobuttonbar,title: KoolCulator") %sets screen graphics to specific dimensions (title is set, toolbar is removed)
colourback (black)   %sets screen background colour to black
cls                  %allows whole screen colour to be set to black


%Main Program for my Calculator

colour (white)    %sets font to white (Only used this for seeing outputted answer while testing my program)

%Global Variables

var xcoordinate : int          %the x coordinate of the button (used for determining if the button has been pressed)
var ycoordinate : int          %the y coordinate of the button (used for determining if the button has been pressed)
var button : int               %the value of the button (used for determining if the mouse has been clicked; set to 0 if no click, 1 if there is a click)
var buttoncheck : boolean      %checks to see if the button has been clicked, if it has been, then if statements are activated
buttoncheck := false           %set to false (button hasn't been pressed); value is either true or false (button has been pressed or hasn't been pressed)
var buttonfont : int           %the declaration of the font used for the number and operation buttons
var offbuttonfont : int        %the declaration of the font used for the off button
var clearbuttonfont : int      %the declaration of the font used for the clear button
var number1 : string := ""     %declaration of the number1 variable which is blank until pressed
var number2 : string := ""     %declaration of the number2 variable which is blank until pressed
var operation : string := ""   %declaration of the operation variable which is blank until pressed
var answer : int               %declares the variable that stores the answer


%Draws the button that the numbers will be outputed to

Draw.FillBox (10, 520, 590, 650, grey)     %draws the area where the numbers are outputed onto the screen

%Draws the first column of buttons for calculator

Draw.FillBox (10, 10, 350, 110, white)       %draws the 0 button onto the screen
Draw.FillBox (10, 130, 110, 240, white)      %draws the 1 button onto the screen
Draw.FillBox (10, 260, 110, 370, white)      %draws the 4 button onto the screen
Draw.FillBox (10, 390, 110, 500, white)      %draws the 7 button onto the screen

%Draws the second column of buttons for calculator

Draw.FillBox (130, 130, 230, 240, white)     %draws the 2 button onto the screen
Draw.FillBox (130, 260, 230, 370, white)     %draws the 5 button onto the screen
Draw.FillBox (130, 390, 230, 500, white)     %draws the 8 button onto the screen

%Draws the third column of buttons for calculator

Draw.FillBox (250, 130, 350, 240, white)     %draws the 3 button onto the screen
Draw.FillBox (250, 260, 350, 370, white)     %draws the 6 button onto the screen
Draw.FillBox (250, 390, 350, 500, white)     %draws the 9 button onto the screen

%Draws the fourth column of buttons for calculator

Draw.FillBox (370, 10, 470, 110, white)     %draws the decimal button onto the screen
Draw.FillBox (370, 130, 470, 240, white)    %draws the addition button onto the screen
Draw.FillBox (370, 260, 470, 370, white)    %draws the  multiplication button onto the screen
Draw.FillBox (370, 390, 470, 500, red)      %draws the delete button onto the screen

%Draws the fifth column of buttons for calculator

Draw.FillBox (490, 10, 590, 110, white)     %draws the equal button onto the screen
Draw.FillBox (490, 130, 590, 240, white)    %draws the subtraction button onto the screen
Draw.FillBox (490, 260, 590, 370, white)    %draws the division onto the screen
Draw.FillBox (490, 390, 590, 500, red)      %draws the off button onto the screen

buttonfont := Font.New ("TimesNewRoman:56")               %declares the value of buttonfont (Times New Roman font with a size of 56)
offbuttonfont := Font.New ("TimesNewRoman:36:bold")       %declares the value of buttonfont (Times New Roman font, bolded with a size of 36)
clearbuttonfont := Font.New ("TimesNewRoman:32:bold")     %declares the value of buttonfont (Times New Roman font, bolded with a size of 36)

Font.Draw ("0", 165, 35, buttonfont, black)     %draws the 0 onto the 0 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("1", 40, 155, buttonfont, black)     %draws the 1 onto the 1 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("2", 160, 155, buttonfont, black)    %draws the 2 onto the 2 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("3", 280, 155, buttonfont, black)    %draws the 3 onto the 3 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("4", 40, 290, buttonfont, black)     %draws the 4 onto the 4 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("5", 160, 290, buttonfont, black)    %draws the 5 onto the 5 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("6", 280, 290, buttonfont, black)    %draws the 6 onto the 6 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("7", 40, 420, buttonfont, black)     %draws the 7 onto the 7 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("8", 160, 420, buttonfont, black)    %draws the 8 onto the 8 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("9", 280, 420, buttonfont, black)    %draws the 9 onto the 9 button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw (".", 408, 53, buttonfont, black)     %draws the . onto the decimal button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("+", 398, 155, buttonfont, black)    %draws the + onto the addition button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("-", 527, 160, buttonfont, black)    %draws the - onto the subtraction button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("x", 402, 290, buttonfont, black)    %draws the x onto the multiplication button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("?", 520, 283, buttonfont, black)    %draws the ? onto the division button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("=", 517, 34, buttonfont, black)     %draws the = onto the equal button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("OFF", 494, 425, offbuttonfont, white)     %draws the OFF onto the off button for the calculator at these coordinates, using black font, using buttonfont
Font.Draw ("DEL", 377, 425, clearbuttonfont, white)   %draws the DEL onto the delete button for the calculator at these coordinates, using black font, using buttonfont
Font.Free (offbuttonfont)                             %used to free the memory used by the font that won't be needed for the rest of the program

loop       % 390 and ycoordinate < 500   %if the off button is pressed, then the program ends
                if xcoordinate > 10 and xcoordinate < 350 and ycoordinate > 10 and ycoordinate < 110 then       %if the mouse was clicked in this area then...
                    number1 := number1 + "0"     %...add 0 to the value of number1
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "1"     %...add 1 to the value of number1
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 130 and ycoordinate < 240 then    %if the mouse was clicked in this area then...
                    number1 := number1 + "2"     %...add 2 to the value of number1
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 130 and ycoordinate < 240 then    %if the mouse was clicked in this area then...
                    number1 := number1 + "3"     %...add 3 to the value of number1
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 260 and ycoordinate < 370 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "4"     %...add 4 to the value of number1
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 260 and ycoordinate < 370 then    %if the mouse was clicked in this area then...
                    number1 := number1 + "5"     %...add 5 to the value of number1
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 260 and ycoordinate < 370 then    %if the mouse was clicked in this area then...
                    number1 := number1 + "6"     %...add 6 to the value of number1
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 390 and ycoordinate < 500 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "7"     %...add 7 to the value of number1
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 390 and ycoordinate < 500 then    %if the mouse was clicked in this area then...
                    number1 := number1 + "8"     %...add 8 to the value of number1
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 390 and ycoordinate < 500 then    %if the mouse was clicked in this area then...
                    number1 := number1 + "9"     %...add 9 to the value of number1
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 10 and ycoordinate < 110 then     %if the mouse was clicked in this area then...
                    number1 := number1 + "."     %...add . to the value of number1
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 390 and ycoordinate < 500 then    %if the mouse was clicked in this area then...
                    number1 := ""     %...clears the number1 off the screen
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 130 and ycoordinate < 240 then    %if the mouse was clicked in this area then...
                    operation := "+"    %...sets the operation to addition and exits the loop
                    exit                %...exits the loop so number2 can be entered
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 260 and ycoordinate < 370 then    %if the mouse was clicked in this area then...
                    operation := "*"    %...sets the operation to multiplication and exits the loop
                    exit                %...exits the loop so number2 can be entered
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 130 and ycoordinate < 240 then    %if the mouse was clicked in this area then...
                    operation := "-" %...sets the operation to subtraction and exits the loop
                    exit             %...exits the loop so number2 can be entered
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 260 and ycoordinate < 370 then    %if the mouse was clicked in this area then...
                    operation := "/" %...sets the operation to division and exits the loop
                    exit             %...exits the loop so number2 can be entered
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 10 and ycoordinate < 110 then     %if the mouse was clicked in this area then...
                    exit             %...exits the loop so the answer can be calculated
                end if               %if statements that controls where the button was pressed is ended
            end if                   %the buttoncheck if statement ends


        else
            if button = 0 then             %if the button hasn't been pressed, then nothing happens
                buttoncheck := false       %buttoncheck is false because nothing has been pressed
            end if                         %ends if statement
        end if

        Font.Draw (number1, 100, 530, buttonfont, black)     %draws the value of number1 onto the screen

        Draw.FillBox (10, 520, 590, 650, grey)               %draws the box where the answer in outputted to

    end loop     % 490 and xcoordinate < 590 and ycoordinate > 390 and ycoordinate < 500 %if the off button is pressed, then the program ends

    loop     % 10 and xcoordinate < 350 and ycoordinate > 10 and ycoordinate < 110 then         %if the mouse was clicked in this area then...
                    number2 := number2 + "0"     %...add 0 to the value of number2
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 130 and ycoordinate < 240 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "1"     %...add 1 to the value of number2
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 130 and ycoordinate < 240 then    %if the mouse was clicked in this area then...
                    number2 := number2 + "2"     %...add 2 to the value of number2
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 130 and ycoordinate < 240 then    %if the mouse was clicked in this area then...
                    number2 := number2 + "3"     %...add 3 to the value of number2
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 260 and ycoordinate < 370 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "4"     %...add 4 to the value of number2
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 260 and ycoordinate < 370 then    %if the mouse was clicked in this area then...
                    number2 := number2 + "5"     %...add 5 to the value of number2
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 260 and ycoordinate < 370 then    %if the mouse was clicked in this area then...
                    number2 := number2 + "6"     %...add 6 to the value of number2
                elsif xcoordinate > 10 and xcoordinate < 110 and ycoordinate > 390 and ycoordinate < 500 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "7"     %...add 7 to the value of number2
                elsif xcoordinate > 130 and xcoordinate < 230 and ycoordinate > 390 and ycoordinate < 500 then    %if the mouse was clicked in this area then...
                    number2 := number2 + "8"     %...add 8 to the value of number2
                elsif xcoordinate > 250 and xcoordinate < 350 and ycoordinate > 390 and ycoordinate < 500 then    %if the mouse was clicked in this area then...
                    number2 := number2 + "9"     %...add 9 to the value of number2
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 10 and ycoordinate < 110 then     %if the mouse was clicked in this area then...
                    number2 := number2 + "."     %...add . to the value of number2
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 390 and ycoordinate < 500 then    %if the mouse was clicked in this area then...
                    number2 := ""     %...clears the number2 off the screen
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 130 and ycoordinate < 240 then    %if the mouse was clicked in this area then...
                    operation := "+"  %...sets the operation to addition and exits the loop
                    exit              %...exits the loop so the answer can be calculated
                elsif xcoordinate > 370 and xcoordinate < 470 and ycoordinate > 260 and ycoordinate < 370 then    %if the mouse was clicked in this area then...
                    operation := "*"  %...sets the operation to multiplication and exits the loop
                    exit              %...exits the loop so the answer can be calculated
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 130 and ycoordinate < 240 then    %if the mouse was clicked in this area then...
                    operation := "-" %...sets the operation to subtraction and exits the loop
                    exit             %...exits the loop so the answer can be calculated
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 260 and ycoordinate < 370 then    %if the mouse was clicked in this area then...
                    operation := "/" %...sets the operation to division and exits the loop
                    exit             %...exits the loop so the answer can be calculated
                elsif xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 10 and ycoordinate < 110 then     %if the mouse was clicked in this area then...
                    exit             %...exits the loop so the answer can be calculated
                end if
            end if

        else
            if button = 0 then           %if the button hasn't been pressed, then nothing happens
                buttoncheck := false     %buttoncheck is false because nothing has been pressed
            end if
        end if

        Font.Draw (number2, 100, 530, buttonfont, black)     %draws the value of number2 onto the text field

        Draw.FillBox (10, 520, 590, 650, grey)               %draws the box where the answer in outputted to

        exit when xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 390 and ycoordinate < 500  %if the off button is pressed, then the program ends

    end loop  % convert to int.
%%num 2 = "string 1 + 0" = string 10 -> conver to int
%%answer = int 50 + int 10 = 60....   get it???


-----------------------------------
Wajih
Mon Jan 17, 2011 1:19 pm

RE:Urgent Help for Calculator Program
-----------------------------------
yeye i get it but is the value of the answer 60 now?

-----------------------------------
Tony
Mon Jan 17, 2011 1:23 pm

RE:Urgent Help for Calculator Program
-----------------------------------
You should be able to answer that.

-----------------------------------
TokenHerbz
Mon Jan 17, 2011 3:15 pm

RE:Urgent Help for Calculator Program
-----------------------------------
You should get into the habbit of testing these things out yourself.  If you cant understand it by reading the code, add a few test lines to make sure it really is INT value of 60...  


put answer - 30  %%outputs 30
put answer - 60  %%outputs 0 (proof value is 60)
put answer + "TEST"  %%will error cause its INT value.


Pretty Basic stuff...

-----------------------------------
Wajih
Mon Jan 17, 2011 7:02 pm

RE:Urgent Help for Calculator Program
-----------------------------------
so would i have to do that for all the numbers? becuase i had to remake my calculator, it now only has 1 set of numbers

-----------------------------------
TokenHerbz
Mon Jan 17, 2011 8:56 pm

RE:Urgent Help for Calculator Program
-----------------------------------
number 1 (string form) += numbers (string) untill expression reached, then convert to int and move to number 2, repeat, when = then int expression int = answer.  if ya get that...

I'm tempted to see if i can make a super overly complicated calculator :P for fun ofcourse, i'd have to make it really confusing tho so all you guys cant use it :P  maybe ill get to it.. lol

-----------------------------------
Wajih
Mon Jan 17, 2011 9:08 pm

RE:Urgent Help for Calculator Program
-----------------------------------
so i have to make num and num2 strings then convert them to ints?

i am also having one more problem, since i had to remake my calculator, both sets of numbers have the same coordinates, num and num2. so say if i hit the number "9" both 9's show up, for num and num2. how do i make it so that if i hit nine, only the nine for num shows up, and not for the num2 until i hit the operator?

-----------------------------------
TokenHerbz
Mon Jan 17, 2011 9:43 pm

RE:Urgent Help for Calculator Program
-----------------------------------
well you just said it, 

how do you know when num1 is done? when the operator is selected right...  then you know to start number 2, then when do you calculate the answer, when the "=" is selected, make some if's or even if you have to, add some variables to keep track!

-----------------------------------
Wajih
Mon Jan 17, 2011 10:37 pm

RE:Urgent Help for Calculator Program
-----------------------------------
ok i get what you are saying but how do i make a code that when an operator is pressed, num stops, and num 2 begins?

do i have to make a new varaible or put in some loops?

-----------------------------------
Tony
Mon Jan 17, 2011 10:46 pm

Re: RE:Urgent Help for Calculator Program
-----------------------------------
do i have to make a new varaible or put in some loops?
Not necessarily, but if that helps you understand your code, then it could be helpful.

-----------------------------------
Wajih
Tue Jan 18, 2011 4:58 pm

RE:Urgent Help for Calculator Program
-----------------------------------
hey token and tony, i crated a buttoncheck variable and it is boolean. if its false then it enters a number, and if its true it only enters an operator. but when its false it still enters an operator, any ideas why?

-----------------------------------
Tony
Tue Jan 18, 2011 5:13 pm

RE:Urgent Help for Calculator Program
-----------------------------------
Probably because you've implemented in a different way than what you are describing. Look closely.

Keep in mind that you wouldn't know that it's time to start entering an operator until an operator button has been pressed.

That is, if your current number so far is 42, you can't know if I'm going to press + (operator) or 1 (to enter 421) next.

-----------------------------------
Wajih
Tue Jan 18, 2011 7:06 pm

RE:Urgent Help for Calculator Program
-----------------------------------
or would i better off declaring buttoncheck as an integer?  

i think it would be easier because it buttoncheck = 1  only  num can be pressed. and after a number is pressed, the buttoncheck value is then 2, which allows to be an operator.
 good?
bad?

-----------------------------------
TokenHerbz
Tue Jan 18, 2011 7:20 pm

RE:Urgent Help for Calculator Program
-----------------------------------
what you mean button check? something like this?? Are you using a class?


    fcn Click_Button (x_, y_ : int) : boolean
        if x_ = pos.x and y_ = pos.y then
            result true
        end if
        result false
    end Click_Button


-----------------------------------
Wajih
Tue Jan 18, 2011 7:28 pm

RE:Urgent Help for Calculator Program
-----------------------------------
whats a class? 
how does it work?

buttoncheck is just a variable i created to mae sure when to hit an integer, or an operator

-----------------------------------
TokenHerbz
Tue Jan 18, 2011 7:29 pm

RE:Urgent Help for Calculator Program
-----------------------------------
oh yeah don't worry about class's yet.

hmm. not sure how yours works can you post it?

-----------------------------------
Wajih
Tue Jan 18, 2011 7:39 pm

RE:Urgent Help for Calculator Program
-----------------------------------
View.Set ("offscreenonly")




%Declaring the Variables
var num : int := 0
var num2 : int := 0
var answer : real := 0
var symbol : string := ""
var x, y, button : int := 0
var state : int := 0
var final : string := ""
var buttoncheck : int := 0







loop
    drawbox (235, 100, 286, 135, black)
    drawbox (340, 290, 400, 350, black)
    drawbox (100, 100, 286, 475, black)
    drawbox (100, 305, 286, 350, black)
    drawbox (100, 100, 165, 135, black)
    drawoval (205, 120, 12, 12, black)
    drawoval (148, 151, 12, 12, black)
    drawoval (205, 151, 12, 12, black)
    drawoval (262, 151, 12, 12, black)
    drawoval (148, 200, 12, 12, black)
    drawoval (205, 200, 12, 12, black)
    drawoval (262, 200, 12, 12, black)
    drawoval (148, 249, 12, 12, black)
    drawoval (205, 249, 12, 12, black)
    drawoval (262, 249, 12, 12, black)
    drawoval (140, 280, 10, 10, blue)
    drawoval (180, 280, 10, 10, red)
    drawoval (228, 280, 10, 10, green)
    drawoval (260, 280, 10, 10, purple)




    %Draws and locates the calculator and the numbers on the calculator


    locate (3, 20)
    put "CALCULATOR" ..
    locate (18, 26)
    put "0" ..
    locate (16, 19)
    put "1" ..
    locate (16, 26)
    put "2" ..
    locate (16, 33)
    put "3" ..
    locate (13, 19)
    put "4" ..
    locate (13, 26)
    put "5" ..
    locate (13, 33)
    put "6" ..
    locate (10, 19)
    put "7" ..
    locate (10, 26)
    put "8" ..
    locate (10, 33)
    put "9" ..




    locate (8, 33)
    put "-" ..
    locate (8, 18)
    put "+" ..
    locate (8, 29)
    put "/" ..
    locate (8, 23)
    put "*" ..
    locate (18, 33)
    put "=" ..
    locate (18, 15)
    put "CLEAR" ..














    %Looping the whole code


    View.Update

if buttoncheck = 0 then
buttoncheck := buttoncheck + 1
 locate (10, 50)
        put buttoncheck
end if




    Mouse.Where (x, y, button)
    Text.Locate (24, 1)
    if button = 0 then
        put x : 0, "  ", y : 0, "  button up"
    else
        put x : 0, "  ", y : 0, "  button down"
    end if

    
   
   
       
        %Gets value of first number
        if (buttoncheck = 1) and (button = 1) and (x >= 196) and (x = 110) and (y = 137) and (x = 142) and (y = 194) and (x = 142) and (y = 251) and (x = 142) and (y = 137) and (x = 190) and (y = 194) and (x = 190) and (y = 251) and (x = 190) and (y = 137) and (x = 241) and (y = 196) and (x < 210) and (y > 237) and (y < 259) then
            locate (5, 14)
            num := 8
            put num ..

            buttoncheck := 2



        elsif (buttoncheck = 1) and (button = 1) and (x >= 251) and (x = 241) and (y = 172) and (x = 273) and (y = 220) and (x = 273) and (y = 130) and (x = 270) and (y = 240) and (x = 270) and (y = 100) and (x = 100) and (y = 196) and (x = 110) and (y = 137) and (x = 142) and (y = 194) and (x = 142) and (y = 251) and (x = 142) and (y = 137) and (x = 190) and (y = 194) and (x = 190) and (y = 251) and (x = 190) and (y = 137) and (x = 241) and (y = 196) and (x < 210) and (y > 237) and (y < 259) then
            locate (5, 19)
            num2 := 8
            put num2 ..
            
        end if




        if (button = 1) and (x >= 251) and (x = 241) and (y = 172) and (x = 273) and (y = 172) and (x = 273) and (y = 220) and (x = 273) and (y = 323) and (x = 271) and (y = 240) and (x = 270) and (y = 235) and (x = 100) and (y 