Calculator

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Omar319
Posts: 14
Joined: Sun Apr 27, 2008 10:57 am

Calculator

Post by Omar319 » Wed Apr 30, 2008 6:58 pm

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

Nonsanity
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 86
Joined: Thu May 17, 2007 9:15 pm
Contact:

Post by Nonsanity » Wed Apr 30, 2008 8:48 pm

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
~ Nonsanity
~ Chris Innanen

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Apr 30, 2008 9:10 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Omar319
Posts: 14
Joined: Sun Apr 27, 2008 10:57 am

Calculator

Post by Omar319 » Wed Apr 30, 2008 9:34 pm

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

Post Reply