Pages: 1
Topic closed
I need help with this, and it is VERY complicated. If you understand how the decimal number system works(Powers of ten for each "place" including after the decimal point)) could you please look at it(And if not, thanks for looking at this anyway.)? Here it is: http://scratch.mit.edu/projects/AlanProjects/375844
Last edited by AlanProjects (2009-01-09 17:44:38)
Offline
Can you explain exactly what it is that your project is supposed to do, and what it is not doing?
Offline
It is supposed to make you able to input a n-digit positive number into a variable using an array. Down array puts in a decimal point, I forgot to write that.
Offline
It is not properly adding the decimal part of a number. It works by separating out each part of a number, the whole part and the part after the decimal point (The 10^-x where x is the xth digit after the decimal point.) and adding them to a variable by the property of the decimal number system that each number "place" is a power of 10. For in stance, to convert 10.24, it sees that 10 is the whole part and .2 is the less-than-1 part. It sees that 0 is the first digit in the whole section, so adds 0*(10^0) to the variable. Then it sees the 1 in the next "place", and adds 1*(10*2) . Then in the negative power(less-than-1) part, It sees 2 and adds 2*(10^-1) to the variable(Or is supposed to. This is where the problem is.) then it adds 4*(10^-2). Calculate that, and that is 10.24 . That is what its supposed to do, but in the script for the negative powers, If "n" or the index variable used to do the powers (10^-1, 10^-2, etc.) and cycle through each element("Place") of the decimal part, equals zero, it looks at item 1 of the decimal part(Its in an array), and multiplies it by 10^(n*-1), which ends up being 0 because n=0. So it adds 0 to the array, when it should add item 1 of the array *-1. Sorry I didn't explain it well enough. This is the longest post i've ever typed.
Offline
I've downloaded your project and had a look at the code. Though the core coding is quite simple, there's lots of other stuff that needed to make it show up properly.
Instead of using the existing code, I've used a different system where by the variable 'Number' is multiplied by 10 and then has the number added to it:
Key 1 pressed
Add 1 to [list] Numbers
When space pressed
Set [var] Number to [var]Number * 10
Add item 1 of [list] Numbers to [var]Number
When the down key is pressed to insert the decimal point, its position is stored even though it is not added to the variable.
So if you put in 123.567 it is stored as 123567 and the decimal's location is 3.
The variable 'Number' is the divided to get it to 123.567. Unfortunately, variables in Scratch are automatically rounded so the only way to store the number properly is in a list.
As well as fixing the error, I've added a decimal places slider and simplified the code. The remixed project can be found here. I have put loads of comments in so you know what all the parts of the script do.
Hope this was of help,
SB
Offline
http://scratch.mit.edu/projects/bhz/370119
Decimals were just added
Offline
Topic closed
Pages: 1