Computer Science Canada

Urgent Help for Calculator Program

Author:  huskiesgoaler34 [ Sat Jan 15, 2011 8:44 pm ]
Post subject:  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 %<=========== LOOP 1: loops the whole program
loop %<=========== LOOP 2: loops the section determining the value of number1
Mouse.Where (xcoordinate, ycoordinate, button) %Mouse.Where checks to see where the mouse is located (x,y coordinates)and if the button was pressed
if buttoncheck = false then %checks to see if the button was pressed (buttoncheck is false because no button was pressed)
if button = 1 then %if the button is pressed (holds a value of 1) then buttoncheck is true
buttoncheck := true %buttoncheck is true because a button was pressed
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 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 %<=========== LOOP 2: ends here

loop %<=========== LOOP 3: loops the section determining the value of number2
Mouse.Where (xcoordinate, ycoordinate, button)
if buttoncheck = false then
if button = 1 then
buttoncheck := true
if xcoordinate > 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
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

[/syntax]

Please specify what version of Turing you are using

4.1.1

Author:  huskiesgoaler34 [ Sat Jan 15, 2011 9:05 pm ]
Post subject:  Re: Urgent Help for Calculator Program

HELP PLEASE!

Author:  Tony [ Sat Jan 15, 2011 9:25 pm ]
Post subject:  RE:Urgent Help for Calculator Program

Quote:

...but it doesn't work...

In what way does it not work...

Author:  huskiesgoaler34 [ Sat Jan 15, 2011 9:43 pm ]
Post subject:  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.

Author:  Tony [ Sat Jan 15, 2011 9:48 pm ]
Post subject:  RE:Urgent Help for Calculator Program

That is too generic. The answer might not be calculated for any number of reasons.

Author:  huskiesgoaler34 [ Sat Jan 15, 2011 9:58 pm ]
Post subject:  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.

Author:  Tony [ Sat Jan 15, 2011 10:05 pm ]
Post subject:  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.

Author:  huskiesgoaler34 [ Sat Jan 15, 2011 10:57 pm ]
Post subject:  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.

Author:  huskiesgoaler34 [ Sat Jan 15, 2011 11:00 pm ]
Post subject:  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.

Author:  Tony [ Sat Jan 15, 2011 11:44 pm ]
Post subject:  Re: Urgent Help for Calculator Program

huskiesgoaler34 @ Sat Jan 15, 2011 10:57 pm wrote:
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
Quote:

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.

Author:  huskiesgoaler34 [ Sun Jan 16, 2011 8:41 am ]
Post subject:  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.

Author:  Tony [ Sun Jan 16, 2011 9:24 am ]
Post subject:  Re: RE:Urgent Help for Calculator Program

Tony @ Sat Jan 15, 2011 10:05 pm wrote:
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.

Author:  huskiesgoaler34 [ Sun Jan 16, 2011 10:39 am ]
Post subject:  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! Very Happy Very Happy

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)

Author:  huskiesgoaler34 [ Sun Jan 16, 2011 11:37 am ]
Post subject:  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

Author:  TokenHerbz [ Sun Jan 16, 2011 11:43 am ]
Post subject:  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?

Author:  huskiesgoaler34 [ Sun Jan 16, 2011 12:10 pm ]
Post subject:  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 %<=========== LOOP 1: loops the whole program
number1 := "" %sets the value of number1 back to 0 (or blank) everytime the loop begins
number2 := "" %sets the value of number2 back to 0 (or blank) everytime the loop begins
operation := "" %sets the operation to 0 (or blank) everytime the loop begins
answer := 0 %sets the answer back to 0 everytime the loop begins
loop %<=========== LOOP 2: loops the section determining the value of number1
Mouse.Where (xcoordinate, ycoordinate, button) %Mouse.Where checks to see where the mouse is located (x,y coordinates)and if the button was pressed
if buttoncheck = false then %checks to see if the button was pressed (buttoncheck is false because no button was pressed)
if button = 1 then %if the button is pressed (holds a value of 1) then buttoncheck is true
buttoncheck := true %buttoncheck is true because a button was pressed
exit when xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 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 %<=========== LOOP 2: ends here

exit when xcoordinate > 490 and xcoordinate < 590 and ycoordinate > 390 and ycoordinate < 500 %if the off button is pressed, then the program ends

loop %<=========== LOOP 3: loops the section determining the value of number2
Mouse.Where (xcoordinate, ycoordinate, button) %Mouse.Where checks to see where the mouse is located (x,y coordinates)and if the button was pressed
if buttoncheck = false then %checks to see if the button was pressed (buttoncheck is false because no button was pressed)
if button = 1 then %if the button is pressed (holds a value of 1) then buttoncheck is true
buttoncheck := true %buttoncheck is true because a button was pressed
if xcoordinate > 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 %<=========== LOOP 3: ends here

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) %draws the value of answer onto the text field

Draw.FillBox (10, 520, 590, 650, grey) %draws the box where the answer in outputted to

end loop %<=========== LOOP 1: ends here

%End of Program

Author:  Tony [ Sun Jan 16, 2011 12:21 pm ]
Post subject:  RE:Urgent Help for Calculator Program

Are you just drawing stuff on top of the answer?
code:

Font.Draw (intstr (answer), 100, 530, buttonfont, red) %draws the value of answer onto the text field

delay(5000)

Draw.FillBox (10, 520, 590, 650, grey) %draws the box where the answer in outputted to

Author:  huskiesgoaler34 [ Sun Jan 16, 2011 12:24 pm ]
Post subject:  Re: Urgent Help for Calculator Program

I LOVE YOU TONY!

I DONATED 5 BITS TO YOU!

Author:  TokenHerbz [ Sun Jan 16, 2011 12:38 pm ]
Post subject:  RE:Urgent Help for Calculator Program

Okay well did you notice if you add "Input.Pause" right above your very last loop in your program, it does infact "display" your results.

What happens is it Goes and restarts your loop tho, and its so fast you don't see it.

So you can do a few things here, But i would suggest adding a long pause or wait for human input before clearing.

i notice another "answer" thats small to appearing behind your gray box up in the corner, should remove that to.

Author:  TokenHerbz [ Sun Jan 16, 2011 12:45 pm ]
Post subject:  RE:Urgent Help for Calculator Program

dang tony stole my bits Sad

Author:  Tony [ Sun Jan 16, 2011 1:34 pm ]
Post subject:  RE:Urgent Help for Calculator Program

Which is hilarious, because I can give myself bits.

@TokenHerbz -- you can have a +1 karma point.

Author:  huskiesgoaler34 [ Sun Jan 16, 2011 1:50 pm ]
Post subject:  Re: Urgent Help for Calculator Program

thanks for helping me you too

P.S. I removed the little answer in the corner, that was just there to allow me to see if it was calculating the answer.

Author:  Wajih [ Sun Jan 16, 2011 1:50 pm ]
Post subject:  RE:Urgent Help for Calculator Program

hey huskies goalie, can you tell me what you did to make your calculator do double digit and higher operations ?

Author:  huskiesgoaler34 [ Sun Jan 16, 2011 2:00 pm ]
Post subject:  Re: Urgent Help for Calculator Program

that's easy: for the variable number1, if a number is pressed, then the value of that number is added on. for exampe, if 3 was pressed, then the value of the number1 variable is 3. if a another number is pressed, let's say 5, then the value of number1 is 35. i had the problem before that the number would actually be 3 and 5 seperate.
number2 follows the same rules.

I don't understand what you mean about higher operations.

Author:  TokenHerbz [ Sun Jan 16, 2011 2:53 pm ]
Post subject:  RE:Urgent Help for Calculator Program

"3" + "5" = "35" --strings
3 + 5 = 8 --ints

strint ("35") + 5 = 40

strint() = string to int
intstr() = int to string

Author:  Tony [ Sun Jan 16, 2011 2:55 pm ]
Post subject:  RE:Urgent Help for Calculator Program

3*10 + 5 = 35; % int

Author:  TokenHerbz [ Sun Jan 16, 2011 3:04 pm ]
Post subject:  RE:Urgent Help for Calculator Program

strint("3" + "5" + "0") + 5 = 355 OR
((3*100) + (5*10) + 0) + 5 = 355. whichevers easier to understand! Razz but tony's ways probly better but i think my way is easier for noobies!

Author:  Wajih [ Sun Jan 16, 2011 3:23 pm ]
Post subject:  RE:Urgent Help for Calculator Program

if the number is added on, wouldnt the number be eight since you pressed 3 and then 5

Author:  TokenHerbz [ Sun Jan 16, 2011 3:27 pm ]
Post subject:  RE:Urgent Help for Calculator Program

test it out..

Author:  Wajih [ Sun Jan 16, 2011 3:36 pm ]
Post subject:  RE:Urgent Help for Calculator Program

by the way my nums are ints not ""( strings) if that helps

Author:  Tony [ Sun Jan 16, 2011 3:41 pm ]
Post subject:  Re: RE:Urgent Help for Calculator Program

Tony @ Sun Jan 16, 2011 2:55 pm wrote:
3*10 + 5 = 35; % int

Author:  Wajih [ Sun Jan 16, 2011 4:10 pm ]
Post subject:  RE:Urgent Help for Calculator Program

how would i put that though,

if button = 1 and num =3 and num = 5 then
num := 3*10+5
end if

something like that?

plz man i just need help on this final project and i will never come here again. i'll even give you all my bits

Author:  Tony [ Sun Jan 16, 2011 4:24 pm ]
Post subject:  RE:Urgent Help for Calculator Program

Look, nobody is going to just give you a complete solution. A working program is just a proxy for checking if you have some basic comprehension of the material, but
Quote:

if ... num =3 and num = 5 ...

shows that this might not be the case.

Go back and re-read all of the replies, there's a lot of good material in there for you to use.

Author:  Wajih [ Sun Jan 16, 2011 5:14 pm ]
Post subject:  RE:Urgent Help for Calculator Program

okay, i read it. i am using ints for my numbers. say if used intstr to display a number and then convert it back to strint, will that number be any number or the original number

Author:  Tony [ Sun Jan 16, 2011 5:18 pm ]
Post subject:  RE:Urgent Help for Calculator Program

try it out
code:

var num:int := 42
put strint(intstr(num))

Author:  Wajih [ Sun Jan 16, 2011 7:10 pm ]
Post subject:  RE:Urgent Help for Calculator Program

it doesnt work

Author:  TokenHerbz [ Sun Jan 16, 2011 7:33 pm ]
Post subject:  RE:Urgent Help for Calculator Program

yes it does, Infact add +8 to the end of the 2nd line, it outputs 50...

Author:  Wajih [ Sun Jan 16, 2011 9:17 pm ]
Post subject:  RE:Urgent Help for Calculator Program

no i get what you are trying to say, but when i put it into my code, i put it into the loop, it said i have too few parameters

Author:  Tony [ Sun Jan 16, 2011 9:28 pm ]
Post subject:  RE:Urgent Help for Calculator Program

Then add the missing parameters.

Author:  Wajih [ Sun Jan 16, 2011 10:59 pm ]
Post subject:  RE:Urgent Help for Calculator Program

ok i did. i made num into num3 because num has already been declared. but how is that number supposed to help me do double digit operations becuase its value doesnt change, it will always be 42. are you implying that i have to create 999 variables and put them into strint? like create them by arraying them?

Author:  Tony [ Sun Jan 16, 2011 11:19 pm ]
Post subject:  Re: RE:Urgent Help for Calculator Program

Because you've asked...
Wajih @ Sun Jan 16, 2011 5:14 pm wrote:
if used intstr to display a number and then convert it back to strint, will that number be any number or the original number

Author:  TokenHerbz [ Mon Jan 17, 2011 2:42 am ]
Post subject:  RE:Urgent Help for Calculator Program

Turing:

var number1 : int %%INT VARIABLES
var number2 : int
var answer : int

%%Number 1 = 5 + 0 for 50 (because we add them ass strings, convert to number after
number1 := strint (intstr (5) + intstr (0))
%%like num = string to int ( int to string (number 1) + ( int to string (other numbers) )
number2 := strint (intstr (1) + intstr (0))
answer := number1 + number2   %%we can add these numbers

put answer %%%out put is 60.  not 5+0+1+0 = 6.  we make it like
%%num 1 = "String 5 + 0" = string 50 -> convert to int.
%%num 2 = "string 1 + 0" = string 10 -> conver to int
%%answer = int 50 + int 10 = 60....   get it???

Author:  Wajih [ Mon Jan 17, 2011 1:19 pm ]
Post subject:  RE:Urgent Help for Calculator Program

yeye i get it but is the value of the answer 60 now?

Author:  Tony [ Mon Jan 17, 2011 1:23 pm ]
Post subject:  RE:Urgent Help for Calculator Program

You should be able to answer that.

Author:  TokenHerbz [ Mon Jan 17, 2011 3:15 pm ]
Post subject:  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...

Turing:

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...

Author:  Wajih [ Mon Jan 17, 2011 7:02 pm ]
Post subject:  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

Author:  TokenHerbz [ Mon Jan 17, 2011 8:56 pm ]
Post subject:  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 Razz for fun ofcourse, i'd have to make it really confusing tho so all you guys cant use it Razz maybe ill get to it.. lol

Author:  Wajih [ Mon Jan 17, 2011 9:08 pm ]
Post subject:  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?

Author:  TokenHerbz [ Mon Jan 17, 2011 9:43 pm ]
Post subject:  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!

Author:  Wajih [ Mon Jan 17, 2011 10:37 pm ]
Post subject:  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?

Author:  Tony [ Mon Jan 17, 2011 10:46 pm ]
Post subject:  Re: RE:Urgent Help for Calculator Program

Wajih @ Mon Jan 17, 2011 10:37 pm wrote:
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.

Author:  Wajih [ Tue Jan 18, 2011 4:58 pm ]
Post subject:  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?

Author:  Tony [ Tue Jan 18, 2011 5:13 pm ]
Post subject:  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.

Author:  Wajih [ Tue Jan 18, 2011 7:06 pm ]
Post subject:  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?

Author:  TokenHerbz [ Tue Jan 18, 2011 7:20 pm ]
Post subject:  RE:Urgent Help for Calculator Program

what you mean button check? something like this?? Are you using a class?

Turing:

    fcn Click_Button (x_, y_ : int) : boolean
        if x_ <= pos.x1 and x_ >= pos.x and y_ <= pos.y1 and y_ >= pos.y then
            result true
        end if
        result false
    end Click_Button

Author:  Wajih [ Tue Jan 18, 2011 7:28 pm ]
Post subject:  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

Author:  TokenHerbz [ Tue Jan 18, 2011 7:29 pm ]
Post subject:  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?

Author:  Wajih [ Tue Jan 18, 2011 7:39 pm ]
Post subject:  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 <= 215) and (y >= 110) and (y <= 130) then
locate (5, 14)
num := 0
put num ..
buttoncheck := 2




elsif (buttoncheck = 1) and (button = 1) and (x >= 137) and (x <= 158) and (y >= 142) and (y <= 163) then
locate (5, 14)
num := 1
buttoncheck := 2
put num ..




elsif (buttoncheck = 1) and (button = 1) and (x >= 194) and (x <= 214) and (y >= 142) and (y <= 163) then
locate (5, 14)
num := 2
put num ..

buttoncheck := 2


elsif (buttoncheck = 1) and (button = 1) and (x >= 251) and (x <= 272) and (y >= 142) and (y <= 163) then
locate (5, 14)
num := 3
put num ..

buttoncheck := 2


elsif (buttoncheck = 1) and (button = 1) and (x >= 137) and (x <= 158) and (y >= 190) and (y <= 208) then
locate (5, 14)
num := 4
put num ..
buttoncheck := 2





elsif (buttoncheck = 1) and (button = 1) and (x >= 194) and (x <= 214) and (y >= 190) and (y <= 208) then
locate (5, 14)
num := 5
put num ..

buttoncheck := 2


elsif (buttoncheck = 1) and (button = 1) and (x >= 251) and (x <= 272) and (y >= 190) and (y <= 208) then
locate (5, 14)
num := 6
put num ..

buttoncheck := 2


elsif (buttoncheck = 1) and (button = 1) and (x >= 137) and (x <= 158) and (y >= 241) and (y <= 258) then
locate (5, 14)
num := 7
put num ..

buttoncheck := 2


elsif (buttoncheck = 1) and (button = 1) and (x >= 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 <= 272) and (y >= 241) and (y <= 258) then
locate (5, 14)
num := 9
put num ..
buttoncheck := 2

end if

if buttoncheck = 1 then
buttoncheck := buttoncheck + 1
locate ( 20, 50)
put buttoncheck
end if
if buttoncheck = 2 then
if (button = 1) and (x >= 172) and (x <= 187) and (y >= 273) and (y <= 290) then
symbol := "*"
locate (5, 17)
put "*" ..
buttoncheck := 3
elsif (button = 1) and (x >= 220) and (x <= 236) and (y >= 273) and (y <= 290) then
symbol := "/"
locate (5, 17)
put "/" ..
buttoncheck := 3
elsif (button = 1) and (x >= 130) and (x <= 150) and (y >= 270) and (y <= 290) then
symbol := "+"
locate (5, 17)
put "+" ..
buttoncheck := 3
elsif (button = 1) and (x >= 240) and (x <= 270) and (y >= 270) and (y <= 290) then
symbol := "-"
locate (5, 17)
put "-" ..
buttoncheck := 3

end if
end if

if (button = 1) and (x >= 100) and (x <= 165) and (y >= 100) and (y <= 135) then
answer := 0
num := 0
num2 := 0
symbol := ""



cls
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)






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" ..


end if







%Gets value of second number















if buttoncheck = 2 then
buttoncheck := 3
end if


if buttoncheck = 3 and (num = 1) or (num = 2) or (num = 3) or (num = 4) or (num = 5) or (num = 6) or (num = 7) or (num = 8) or (num = 9) or (num = 0) then
if (button = 1) and (x >= 196) and (x <= 215) and (y >= 110) and (y <= 130) then
locate (5, 19)
num2 := 0
put num2 ..


end if


if (button = 1) and (x >= 137) and (x <= 158) and (y >= 142) and (y <= 163) then
locate (5, 19)
num2 := 1
put num2 ..

end if


if (button = 1) and (x >= 194) and (x <= 214) and (y >= 142) and (y <= 163) then
locate (5, 19)
num2 := 2
put num2 ..

end if


if (button = 1) and (x >= 251) and (x <= 272) and (y >= 142) and (y <= 163) then
locate (5, 19)
num2 := 3
put num2 ..

end if


if (button = 1) and (x >= 137) and (x <= 158) and (y >= 190) and (y <= 208) then
locate (5, 19)
num2 := 4
put num2 ..



end if


if (button = 1) and (x >= 194) and (x <= 214) and (y >= 190) and (y <= 208) then
locate (5, 19)
num2 := 5
put num2 ..

end if


if (button = 1) and (x >= 251) and (x <= 272) and (y >= 190) and (y <= 208) then
locate (5, 19)
num2 := 6
put num2 ..

end if


if (button = 1) and (x >= 137) and (x <= 158) and (y >= 241) and (y <= 258) then
locate (5, 19)
num2 := 7
put num2 ..

end if


if (button = 1) and (x >= 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 <= 272) and (y >= 241) and (y <= 258) then
locate (5, 19)
num2 := 9
put num2 ..

end if
end if





if (button = 1) and (x >= 172) and (x <= 187) and (y >= 273) and (y <= 290) then
symbol := "*"
locate (5, 17)
put "*" ..




end if


if (button = 1) and (x >= 172) and (x <= 187) and (y >= 273) and (y <= 290) then
symbol := "*"
locate (5, 17)
put "*" ..




end if


if (button = 1) and (x >= 220) and (x <= 236) and (y >= 273) and (y <= 290) then
symbol := "/"
locate (5, 17)
put "/" ..


end if


if (button = 1) and (x >= 323) and (x <= 341) and (y >= 271) and (y <= 290) then
symbol := "+"
locate (5, 17)
put "+" ..


end if


if (button = 1) and (x >= 240) and (x <= 240) and (y >= 270) and (y <= 290) then
symbol := "-"
locate (5, 17)
put "-" ..




end if













%Process the two numbers and decides to add, multiply, divide, or subtract them
if symbol = "*" and final = "=" then
answer := num * num2
locate (5, 46)
put answer ..
elsif symbol = "/" and final = "=" then
answer := num / num2
locate (5, 46)
put answer ..
elsif symbol = "+" and final = "=" then
answer := num + num2
locate (5, 46)
put answer ..
elsif symbol = "-" and final = "=" then
answer := num - num2
locate (5, 46)
put answer ..
end if




if (button = 1) and (x >= 235) and (x <= 286) and (y >= 100) and (y <= 135) then
final := "="
end if
locate (1, 1)
put "Welcome to" ..
locate (2, 1)
put "Wajihs Basic" ..
locate (3, 1)
put "Calculator" ..
end loop
% End of program


i had to post all of it because i am having a problem. num wont display,

can you test it out and tell me what is the problem?

Author:  Wajih [ Tue Jan 18, 2011 8:36 pm ]
Post subject:  RE:Urgent Help for Calculator Program

plz help its due on friday

Author:  Tony [ Tue Jan 18, 2011 8:41 pm ]
Post subject:  RE:Urgent Help for Calculator Program

That's _plenty_ of time. Though considering that you still have things like
code:

num := 1

I can tell that you are not really following up on any advice given out so far. I think your best bet right now is to schedule some time with your teacher to go over your program in person.

Author:  TokenHerbz [ Tue Jan 18, 2011 11:59 pm ]
Post subject:  RE:Urgent Help for Calculator Program

/agreed


: