Pages: 1
Topic closed
Hi my name is chris and i live in australia, currently in year 11 and completing a computing course. In this we use the program scratch which i am not the best at so and help is appreciated.
Our latest project is to create a working calculator on scratch, including all the numbers and watever a calculator has basically, only a simple one not a scientific and that haha
Im not asking some one to just send me or give me a link to one, i would love for some one to help me and teach me the ways on how i would go about doing this, as my teacher is very busy man helping everyone aswell. Any help will be greatly appreciated,
Kind Regards, Chris
Offline
Most approaches to building a simple calculator that I can think of involve creating at least three variables: the first input number, the second input number and the output number. You can call them whatever you want. Then, you will need two more things, a way to enter values for the input numbers and a way to calculate the output number. A very simple approach to the input problem would be to use the slider form on the variables. You can switch a variable to allow slider input by right-clicking on the variable's watcher on the stage. Next, you need a way to know what operation to perform on the input numbers to produce the output number. One simple approach would be to use separate sprites for the different operations ( Addition, Subtraction, etc). Then, you could perform the operation and assign the result using the On Click action for the sprites.
So that would be a simple calculator. There is room for improvement, particularly in the number input area, but why don't you give that a try first.
Offline
what you just sed made no sense to me waht so ever
im not good with scratch, i missed a few lessons due to sickness, when he was teaching variables and what not.
I need a more explanotiry write up lol i basically have no clue how to use the program, with the variables n sutff
Offline
I should try to make a pretty advanced calculator sometime. It would be fun. If you used buttons instead of sliders it would act and look a lot better.
Offline
newareagle wrote:
I should try to make a pretty advanced calculator sometime. It would be fun. If you used buttons instead of sliders it would act and look a lot better.
I tried once. It was hard. I actually had it all planned out with arrays for pretty big numbers, but than I forgot XD though it seems they arrays were working good!
Offline
Don't rush in... look at other projects, test blocks and create simple projects then you'll soon get better and better!
Offline
I'll try to explain it from the very beginning, and without getting too technical... but this will just drag on.
First, open the scratch program.In the top left hand corner you should see a bunch of tabs (motion, looks, sound, etc.) Click on the "variables" tab, then click Add Variable. Name it "value 1" (actually, the name doesn't matter at all when using variables, so name them whatever you like). Add two more: "value 2" & "answer". Now, I'm not going to get complicated by making buttons and everything (so don't worry). Each variable should have shown up on the place with the cat (you can delete the cat if you want, just press the scissors button in the place with all the buttons on top.) Double click on value 1 and value 2 variables (NOT answer) until both of them have a slider underneath. You can also right-click (ctrl+click on a Mac) and set the slider min and max, which sets the limit the slider change the value of the variable to. Try dragging the slider... the number should increase and decrease. You can also drag the variable displayer around the screen to make it go to different spots (which you will HAVE to do to avoid cluttering parts of the screen).
I'd also reccomend editing the background so it's more interesting. press the blank white thing with "stage'' written under it in the part underneath the place displaying the variables, go to backgrounds and press "edit" and just draw something... you can arrange the variables after you're done to fit the background.
Now for the best part: coding.
Put this code into the background:
<when green flag clicked>
<forever>
<if><key[ a ]pressed?>
<set{ answer }to( (( <{ value 1 }> <+> <{ value 2 }> ))
<end>
<if><key[ s ]pressed?>
<set{ answer }to( (( <{ value 1 }> <-> <{ value 2 }> ))
<end>
<if><key[ m ]pressed?>
<set{ answer }to( (( <{ value 1 }> <*> <{ value 2 }> ))
<end>
<if><key[ d ]pressed?>
<set{ answer }to( (( <{ value 1 }> </> <{ value 2 }> ))
<end>
<end>
[/blocks]
And I'm pretty sure you'll have a working calculator.
HOW TO USE IT: Drag the value 1 and value 2 sliders to the numbers you want for the two math values. Then press A to add the numbers, S to subtract them, M to multiply them and D to divide them.
Or was that too detailed? It took over an hour to write...
Last edited by hmnwilson (2008-08-07 18:03:47)
Offline
hmnwilson wrote:
I'll try to explain it from the very beginning, and without getting too technical... but this will just drag on.
First, open the scratch program.In the top left hand corner you should see a bunch of tabs (motion, looks, sound, etc.) Click on the "variables" tab, then click Add Variable. Name it "value 1" (actually, the name doesn't matter at all when using variables, so name them whatever you like). Add two more: "value 2" & "answer". Now, I'm not going to get complicated by making buttons and everything (so don't worry). Each variable should have shown up on the place with the cat (you can delete the cat if you want, just press the scissors button in the place with all the buttons on top.) Double click on value 1 and value 2 variables (NOT answer) until both of them have a slider underneath. You can also right-click (ctrl+click on a Mac) and set the slider min and max, which sets the limit the slider change the value of the variable to. Try dragging the slider... the number should increase and decrease. You can also drag the variable displayer around the screen to make it go to different spots (which you will HAVE to do to avoid cluttering parts of the screen).
I'd also reccomend editing the background so it's more interesting. press the blank white thing with "stage'' written under it in the part underneath the place displaying the variables, go to backgrounds and press "edit" and just draw something... you can arrange the variables after you're done to fit the background.
Now for the best part: coding.
Make a new sprite (it doesn't matter too much what you draw). Now put this code into the new sprite:
<when green flag clicked>
<forever>
<if><key[ a ]pressed?>
<set{ answer }to( (( <{ value 1 }> <+> <{ value 2 }> ))
<end>
<if><key[ s ]pressed?>
<set{ answer }to( (( <{ value 1 }> <-> <{ value 2 }> ))
<end>
<if><key[ m ]pressed?>
<set{ answer }to( (( <{ value 1 }> <*> <{ value 2 }> ))
<end>
<if><key[ d ]pressed?>
<set{ answer }to( (( <{ value 1 }> </> <{ value 2 }> ))
<end>
<end>
[/blocks]
And I'm pretty sure you'll have a working calculator.
HOW TO USE IT: Drag the value 1 and value 2 sliders to the numbers you want for the two math values. Then press A to add the numbers, S to subtract them, M to multiply them and D to divide them.
Or was that too detailed? It took over an hour to write...
Thankyou so much for the very depth reply, i really appreciate it.
When i get home i will have a look at it and see if i can get it working, i send my kindest regards to you sir. Thankyou. I will let you know if i have any problems.
Thankyou once again.
Offline
c_unit wrote:
hmnwilson wrote:
I'll try to explain it from the very beginning, and without getting too technical... but this will just drag on.
First, open the scratch program.In the top left hand corner you should see a bunch of tabs (motion, looks, sound, etc.) Click on the "variables" tab, then click Add Variable. Name it "value 1" (actually, the name doesn't matter at all when using variables, so name them whatever you like). Add two more: "value 2" & "answer". Now, I'm not going to get complicated by making buttons and everything (so don't worry). Each variable should have shown up on the place with the cat (you can delete the cat if you want, just press the scissors button in the place with all the buttons on top.) Double click on value 1 and value 2 variables (NOT answer) until both of them have a slider underneath. You can also right-click (ctrl+click on a Mac) and set the slider min and max, which sets the limit the slider change the value of the variable to. Try dragging the slider... the number should increase and decrease. You can also drag the variable displayer around the screen to make it go to different spots (which you will HAVE to do to avoid cluttering parts of the screen).
I'd also reccomend editing the background so it's more interesting. press the blank white thing with "stage'' written under it in the part underneath the place displaying the variables, go to backgrounds and press "edit" and just draw something... you can arrange the variables after you're done to fit the background.
Now for the best part: coding.
Make a new sprite (it doesn't matter too much what you draw). Now put this code into the new sprite:
<when green flag clicked>
<forever>
<if><key[ a ]pressed?>
<set{ answer }to( (( <{ value 1 }> <+> <{ value 2 }> ))
<end>
<if><key[ s ]pressed?>
<set{ answer }to( (( <{ value 1 }> <-> <{ value 2 }> ))
<end>
<if><key[ m ]pressed?>
<set{ answer }to( (( <{ value 1 }> <*> <{ value 2 }> ))
<end>
<if><key[ d ]pressed?>
<set{ answer }to( (( <{ value 1 }> </> <{ value 2 }> ))
<end>
<end>
[/blocks]
And I'm pretty sure you'll have a working calculator.
HOW TO USE IT: Drag the value 1 and value 2 sliders to the numbers you want for the two math values. Then press A to add the numbers, S to subtract them, M to multiply them and D to divide them.
Or was that too detailed? It took over an hour to write...Thankyou so much for the very depth reply, i really appreciate it.
When i get home i will have a look at it and see if i can get it working, i send my kindest regards to you sir. Thankyou. I will let you know if i have any problems.
Thankyou once again.
If you aren't worrying about looks, than that will work perfectly. Making buttons is way more complex. So if you are just after simplicity, go with that
Offline
Paddle2See wrote:
Most approaches to building a simple calculator that I can think of involve creating at least three variables: the first input number, the second input number and the output number. You can call them whatever you want. Then, you will need two more things, a way to enter values for the input numbers and a way to calculate the output number. A very simple approach to the input problem would be to use the slider form on the variables. You can switch a variable to allow slider input by right-clicking on the variable's watcher on the stage. Next, you need a way to know what operation to perform on the input numbers to produce the output number. One simple approach would be to use separate sprites for the different operations ( Addition, Subtraction, etc). Then, you could perform the operation and assign the result using the On Click action for the sprites.
So that would be a simple calculator. There is room for improvement, particularly in the number input area, but why don't you give that a try first.
Goch took the time to illustrate my approach (along with a lot of other useful things) in this project. It's around page 17 or so.
http://scratch.mit.edu/projects/goch/233542
Offline
I probably should have mentioned... if you put that script into the background, the same thing will happen. You can basically make a working calculator with no sprites whatsoever.
I'll edit the post to make it simpler.
Last edited by hmnwilson (2008-08-07 17:59:50)
Offline
This is probably over with, but hey, if you ever need to make a more advanced calculator, I just made one that uses arrays. It is very convenient and works when downloaded
Offline
i have a working calculator, and it's fine but i want to know how to make it so that it recognises if it's a number or a letter, i have it set so that it basicly asks you what you want to do, add subtract, multiply, or divide, then it asks for the 2 numbers then calcualtes them and tells you the answer, but the problem is, i can put letters into the number spot, and i'm trying to figure out how to make it so that it sees that there are numbers and goes "those don't go there" and re-asks for the numbers, i already know variables, and i'm pretty good with scratch but this just escapes me.
Offline
Topic closed
Pages: 1