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

#1 2011-09-07 01:07:21

djrox
New Scratcher
Registered: 2011-09-07
Posts: 3

How to do make this algorithm work in scratch

Display "Enter x"
Get x
Display "Enter y"
Get y
Set result to 1
While (y > 0)
   Set result to result * x
   Set y to y - 1
Display "The value of x raised to the power y is "
Display result

Offline

 

#2 2011-09-07 02:23:25

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: How to do make this algorithm work in scratch

Would this work for you?

http://img98.imageshack.us/img98/8833/419scriptforcalculating.png


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#3 2011-09-07 08:29:28

cpumaster930
Scratcher
Registered: 2009-02-23
Posts: 100+

Re: How to do make this algorithm work in scratch

Jonathanpb wrote:

Would this work for you?

http://img98.imageshack.us/img98/8833/4 … lating.png

Just to challenge that a little bit: what if you had a fractional exponent?  Then the repeat wouldn't quite work  wink

Try this:
http://i.imgur.com/u7Ftv.gif

The only problem is due to logarithm and exponent rounding, the answer will be a little off, but only by an extremely minute amount.
For example, it says 5^5 = 3124.999999999994.
I think it's obvious the answer is 3125, but if it's part of a script I'd suggest rounding it to the nearest thousandth or something for accuracy.  wink


http://i.imgur.com/Qd0lu.png

Offline

 

Board footer