Here's a upgraded routine for those of you working on the Calculator course. Our observations:
1. A leading "." was not preceded by a leading zero (merely aesthetics)
2. It was possible to enter multiple "." in a number
Update the code on the Card Script
Code: Select all
on numberPressed pNumPress
--if the text of field "display" is 0 then
if lNewNumber is true then
-- determine if we need a leading zero
if pNumPress = "." then
put "0" into field "display"
put pNumPress after field "display"
put false into lNewNumber
else
put pNumPress into field "display"
put false into lNewNumber
end if
else
-- allow only one "."
if pNumPress = "." then
if field "display" contains "." then exit numberPressed
end if
put pNumPress after field "display"
end if
set the label of button "clear" to "C"
textUpdated
end numberPressed
MadDogDean