This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-06-08 13:22:01

pawstu
Scratcher
Registered: 2009-03-20
Posts: 2

Calculator Troubles

My Calculator project doesn't seem to work. I am trying to make decimal numbers work and so far this is my script:

Decimal point button:
<when[ Decimal Button ]clicked>
<set{ Decimal  }to( 1 )>

Number 1 button
<when[ 1 ]clicked>
<if><( <{ Decimal  }> <=> 0 )>
<set{ Calculator Display  }to( (( Calculator Display  <*> 10  ))>
<change{ <{ Calculator Display  }> }by( 1 )>
<else>
<change{ <{ Calculator Display  }> }by( (( 1  </> 10^ Decimal  )) (Didn't know how to get 10^ block)
<change{ <{ Decimal  }> }by( 1 )>

It works once to get X.1 but I can't get X.11 ect. any reason why?


Try out the beta of [url=http://scratch.mit.edu/projects/pawstu/462548tRoly Poly[/url]full version coming soon!

Offline

 

#2 2009-06-09 03:20:57

Chrischb
Scratcher
Registered: 2008-07-24
Posts: 1000+

Re: Calculator Troubles

I never exactly got around to adding decimal points in my calculator... at least it has decimal point answers to division problems such as 2/1.

Anyway, I played around with this for a while and remembered the exact reason I didn't use a variable before; they won't set to something such as 1.111111 very well (I did some tests and got something wacky such as 1.2111111e). I used a list instead, and came up with:

When Green Flag Clicked:
delete all of numbers
delete all of decimal
add [0] to decimal
add { } to numbers

When Space Key Pressed:
if item 1 of decimal ( < [10])
   replace (item 1 of decimal) with [10]

When 1 Key Pressed:
if item 1 of decimal (< [0])
   repeat until (((item 1 of numbers) mod [1]) = [0])
      replace (item 1 of numbers) with ((item 1 of numbers) * [10])
   replace (item 1 of numbers) with ((((item 1 of numbers) * [10]) + [1]) / Decimal)
   replace (item 1 of decimal) with ((item 1 of decimal) * [10])
else
   replace (item 1 of numbers) with (((item 1 of numbers) * [10]) + [1])

Sorry that I couldn't use the forum blocks; there aren't any list ones, and also; sorry for making this post all weird.

Anyway, hope this helps!

Last edited by Chrischb (2009-06-23 01:40:15)


I fall: It's a tragedy. You fall: It's comedy.
Hmph enjoy your fall - I get a lovely spring... without pans of new leaves.

Offline

 

Board footer