turing help...........calculator
Author |
Message |
321534299
|
Posted: Thu Jun 04, 2009 10:06 pm Post subject: turing help...........calculator |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <%Set screen up
import GUI
setscreen ("nocursor")
setscreen ("noecho")
%Declaration Section
var mainWin := Window.Open ("position :center;center,graphics:640;480")
var error : boolean := false
var mainMenubutton, userInputbutton, goodByebutton, buttonnumber1, buttonnumber2, buttonnumber3, buttonnumber4, buttonnumber5, buttonnumber6, buttonnumber7, buttonnumber8, buttonnumber9,
buttonnumber0 : int := 0
var buttonsignplus, buttonsignminus, buttonsigndivide, buttonsignmultiply, buttonsignclear, buttonsignequal : int := 0
var pictureID : int
var numbers : array 1 .. 999 of int
%Draws picture
pictureID := Pic.FileNew ("calculator.jpg")
% program title
procedure title (programTitle : string)
var len : int := length (programTitle)
cls
locate (1, 40 - len div 2)
put programTitle
put ""
end title
% pause program
procedure pauseProgram
var reply : string (1)
put ""
put "Press any key to continue...."
getch (reply)
end pauseProgram
% program introduction
procedure introduction
title ("Calculator")
Pic.Draw (pictureID, 100, -50, picMerge)
locate (3, 1)
put "Let's calculate!!" ..
GUI.Show (mainMenubutton)
end introduction
%Good Bye
procedure goodBye
title ("Calculator")
for x : 0..500
put "Thanks for using the calculator!!"
put "Created by: john doe"
put ""
put "For more info call: 416-967-1111"
drawfillstar (0+x, 0, 50+x, 50, yellow)
loop
exit when hasch
end loop
Window.Close (mainWin)
end for
end goodBye
%Main Menu
procedure mainMenu
title ("Calculator")
Pic.Draw (pictureID, 100, -50, picMerge)
put "Please select one of the following!" ..
GUI.Show (userInputbutton)
GUI.Show (goodByebutton)
end mainMenu
%UserInput
procedure userInput
title ("Calculator")
put "Please press the buttons on the screen to calculate."
GUI.Show (buttonnumber0)
GUI.Show (buttonnumber1)
GUI.Show (buttonnumber2)
GUI.Show (buttonnumber3)
GUI.Show (buttonnumber4)
GUI.Show (buttonnumber5)
GUI.Show (buttonnumber6)
GUI.Show (buttonnumber7)
GUI.Show (buttonnumber8)
GUI.Show (buttonnumber9)
GUI.Show (buttonsignplus)
GUI.Show (buttonsignminus)
GUI.Show (buttonsigndivide)
GUI.Show (buttonsignmultiply)
GUI.Show (buttonsignequal)
GUI.Show (buttonsignclear)
GUI.Show (mainMenubutton)
end userInput
proc clss
userInput
end clss
proc one
put "1" ..
end one
proc two
put "2" ..
end two
proc three
put "3" ..
end three
proc four
put "4" ..
end four
proc five
put "5" ..
end five
proc six
put "6" ..
end six
proc seven
put "7" ..
end seven
proc eight
put "8" ..
end eight
proc nine
put "9" ..
end nine
proc zero
put "0" ..
end zero
proc plus
put "+" ..
end plus
proc minus
put "-" ..
end minus
proc divide
put "/" ..
end divide
proc multiply
put "*" ..
end multiply
proc equal
put "=" ..
end equal
%Buttons
mainMenubutton := GUI.CreateButton (10, 10, 0, "Main Menu", mainMenu)
userInputbutton := GUI.CreateButton (10, 260, 0, "Let's calculate!", userInput)
goodByebutton := GUI.CreateButton (10, 190, 0, "Exit", goodBye)
buttonnumber1 := GUI.CreateButton (300, 260, 10, "1", one)
buttonnumber2 := GUI.CreateButton (350, 260, 10, "2", two)
buttonnumber3 := GUI.CreateButton (400, 260, 10, "3", three)
buttonnumber4 := GUI.CreateButton (300, 240, 10, "4", four)
buttonnumber5 := GUI.CreateButton (350, 240, 10, "5", five)
buttonnumber6 := GUI.CreateButton (400, 240, 10, "6", six)
buttonnumber7 := GUI.CreateButton (300, 220, 10, "7", seven)
buttonnumber8 := GUI.CreateButton (350, 220, 10, "8", eight)
buttonnumber9 := GUI.CreateButton (400, 220, 10, "9", nine)
buttonnumber0 := GUI.CreateButton (300, 200, 10, "0", zero)
buttonsignplus := GUI.CreateButton (450, 260, 10, "+", plus)
buttonsignminus := GUI.CreateButton (450, 240, 10, "-", minus)
buttonsigndivide := GUI.CreateButton (450, 220, 10, "/", divide)
buttonsignmultiply := GUI.CreateButton (450, 200, 10, "*", multiply)
buttonsignequal := GUI.CreateButton (350, 198, 86, "=", equal)
buttonsignclear := GUI.CreateButton (300, 300, 10, "clear", clss)
%Main Program
introduction
loop
exit when GUI.ProcessEvent
end loop
goodBye
%End Program
>
What is the problem you are having?
<im trying to make a calculator program using buttons, howver buttons need to go to a procedure, how can i make a procedure represent a number and then store it?>
Describe what you have tried to solve this problem
<ive tried arrays and GUI.GetEventWidgetID>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
andrew.
|
Posted: Sat Jun 06, 2009 9:28 pm Post subject: RE:turing help...........calculator |
|
|
When you press the buttons on the calculator, instead of just adding 1, 2, 3, etc. to the display, add it to a string.
e.g. Turing: | procedure one
numStr + = "1"
cls
put numStr
end one |
instead of
Turing: | procedure one
put 1 ..
end one |
Then you can have a procedure that takes numStr and does whatever is in there. You can call that procedure when you press the equals button. |
|
|
|
|
 |
321534299
|
Posted: Sun Jun 07, 2009 3:40 pm Post subject: RE:turing help...........calculator |
|
|
lol sry but i dont rly understand.....
so how would my display look? and would that mean i call numStr as a string? |
|
|
|
|
 |
|
|