Here is the problem that I want to code in scratch:-
"Prompt a user to enter a number. Get the number, add 5 to it and then double the sum. Display the final number after doubling."
I couldn't figure out two things: - (1) How to get a number (say 3) from a user and then assign it to a variable (say number1), and then (2) How to add 3 to number (number1+3)
Would someone help me in coding this in scartch, please?
Rana
Offline
The easiest way to get a number from the user is to create a variable and display it on the screen. Then, right-click on the variable and set it to Slider mode which will allow the user to enter a value from zero to 100. Right-click again and you can set the limits of the slider, if you want something different. If you are using a Mac computer, I think it is Opt-Click or something instead of Right-click.
So with the slider variable, you will probably want go have a starting value set on the Green Flag
[blocks]
<when green flag clicked>
<set{ Number1 }to( 0
[/blocks]
You can use the default cat sprite to do the calculation and display the output when it is clicked
[blocks]
<when[ Sprite 1 ]clicked>
<set{ Number 1 }to( (( 2 <*> (( Number 1 <+> 5 )) ))
<say[ Number 1 ]for( 10 )secs>
[/blocks]
Last edited by Paddle2See (2008-03-06 08:31:14)
Offline
You can use a bank of "If (number key) pressed" statements in a loop to input a multi digit number, or put a numeric keypad made of sprites on screen.
Offline
You can find numeric keypad entry already written for you in various calculator projects, for example, my RPN calculator:
http://scratch.mit.edu/projects/kevin_karplus/76772
Offline