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

#1 2008-07-30 05:17:04

c_unit
Scratcher
Registered: 2008-07-30
Posts: 4

Help! Making a calculator on scratch for school, need all the help =)

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

 

#2 2008-07-30 06:10:12

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Help! Making a calculator on scratch for school, need all the help =)

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.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2008-08-03 09:16:59

c_unit
Scratcher
Registered: 2008-07-30
Posts: 4

Re: Help! Making a calculator on scratch for school, need all the help =)

what you just sed made no sense to me waht so ever  tongue 
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

 

#4 2008-08-03 11:34:47

newareagle
Scratcher
Registered: 2008-06-10
Posts: 100+

Re: Help! Making a calculator on scratch for school, need all the help =)

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.


My Guitar Hero Game.
8/9 Projects on the Front Page at Once!

Offline

 

#5 2008-08-03 13:08:04

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: Help! Making a calculator on scratch for school, need all the help =)

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!


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#6 2008-08-03 13:31:35

registeel
Scratcher
Registered: 2008-04-27
Posts: 500+

Re: Help! Making a calculator on scratch for school, need all the help =)

Don't rush in... look at other projects, test blocks and create simple projects then you'll soon get better and better!

Offline

 

#7 2008-08-03 20:32:56

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Help! Making a calculator on scratch for school, need all the help =)

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)


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#8 2008-08-05 19:50:07

c_unit
Scratcher
Registered: 2008-07-30
Posts: 4

Re: Help! Making a calculator on scratch for school, need all the help =)

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

 

#9 2008-08-05 19:52:04

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: Help! Making a calculator on scratch for school, need all the help =)

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


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#10 2008-08-06 07:30:16

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Help! Making a calculator on scratch for school, need all the help =)

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


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#11 2008-08-07 17:54:50

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: Help! Making a calculator on scratch for school, need all the help =)

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)


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#12 2008-08-08 05:49:31

c_unit
Scratcher
Registered: 2008-07-30
Posts: 4

Re: Help! Making a calculator on scratch for school, need all the help =)

you have no idea how much help you guys were, i got it all working, changed it around a bit and now making on a more difficult task. You guys are awesome! two thumbsup  wink

Offline

 

#13 2008-08-25 19:50:21

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: Help! Making a calculator on scratch for school, need all the help =)

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


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#14 2010-03-29 14:09:34

RavenNigthsong
Scratcher
Registered: 2010-03-29
Posts: 1

Re: Help! Making a calculator on scratch for school, need all the help =)

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

 

Board footer