Page 1 of 1

Calculator

Posted: Wed Apr 30, 2008 6:58 pm
by Omar319
Hiya,
For my A Level coursework we had practice on making programs before we started on the assessment tasks and one of them was a calculator: add/divide/subtract/multiply two text fields together and put the answer into an answer field.

But now I want to create another calculator much like the Windows' or Mac calculator: click buttons and it puts the numbers on one line (an a decimal point too), press a function button (+ / * -), the screen clears using the put empty command and stores it in memory by using the command like

Code: Select all

put ####### into MemoryStore
where ##### is whatever has been inputted, then input more characters, then '=' putting the answer in the same field.

I tried creating it but I don't know how to get text to appear on one line.
If I had help with the code for one number, a function, the next number and the answer that'd be great :D

Thanks
Omar :)

Posted: Wed Apr 30, 2008 8:48 pm
by Nonsanity
Here's a bit of code, but all jumbled together. (Can't do ALL your homework for you!) :)

Code: Select all

-- prep work
put true into gIsFirstDigit
put 0 into gLastNum
-- hitting 1
if gIsFirstDigit then put "" into fld "display"
put "1" after fld "display"
put false into gIsFirstDigit
-- hitting 5
if gIsFirstDigit then put "" into fld "display"
put "5" after fld "display"
put false into gIsFirstDigit
-- hitting +
set gMode to "add" 
put fld "display" into gLastNum
put true into gIsFirstDigit
-- hitting 2
if gIsFirstDigit then put "" into fld "display"
put "2" after fld "display"
put false into gIsFirstDigit
-- hitting =
if gMode is "add" then
put gLastNum + fld "display" into fld "display"
put true into gIsFirstDigit

Posted: Wed Apr 30, 2008 9:10 pm
by Mark
Hi Omar,

Open the documentation, go to Getting Started. Click on Ten Function Examples. Select "Simple Calculator - Using Logic". Click on the Launch button. Is that what you're trying to achieve?

Best,

Mark

Calculator

Posted: Wed Apr 30, 2008 9:34 pm
by Omar319
Hi,
Thanks for replying Mark and nonsanity. The coding provided is fine for the numbers but I think I needed to have made the gMode variable first. The documentation helps too as this is what I've been looking for.

Thanks to your replies,
Omar :D