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

#1 2012-08-23 20:48:25

Flycon2002
Scratcher
Registered: 2011-03-26
Posts: 21

Calculator script gone wrong!

Is this correct? if not please help!
I am ten.

when gf clicked
ask [what is your operator? +,-,*,and /] and wait
if < (awnser) = [+]>
set [awnser v] to < (value1) + (value2)>
end
broadcast [add v]
if < (awnser) = [-]>
set [awnser v] to < (value1) - (value2)>
broadcast [sub v]
end
if < (awnser) = [*]>
set [awnser v] to < (value1) * (value2)>
broadcast [multi v]
end
if < (awnser) = [/]>
set [awnser v] to < (value1) / (value2)>
broadcast [div v]
end

When I recive [add v]
ask [what do you want to add (first number)] and wait
set [value1 v] to (awnser)
ask [what do you want to add (second number)] and wait
set [value2 v] to  (awnser)
say [ithink]
say [(value1)]
say [plus]
say [(value2)]
say [is]
say [(awnser)]
then i did all the other when i recive stuff and my kitty thinks all the things i ask it are zero

Offline

 

#2 2012-08-23 22:07:35

curiouscrab
Scratcher
Registered: 2012-06-25
Posts: 100+

Re: Calculator script gone wrong!

Flycon2002 wrote:

Is this correct? if not please help!
I am ten.

when gf clicked
ask [what is your operator? +,-,*,and /] and wait
if < (awnser) = [+]>
set [awnser v] to < (value1) + (value2)>
end
broadcast [add v]
if < (awnser) = [-]>
set [awnser v] to < (value1) - (value2)>
broadcast [sub v]
end
if < (awnser) = [*]>
set [awnser v] to < (value1) * (value2)>
broadcast [multi v]
end
if < (awnser) = [/]>
set [awnser v] to < (value1) / (value2)>
broadcast [div v]
end

When I recive [add v]
ask [what do you want to add (first number)] and wait
set [value1 v] to (awnser)
ask [what do you want to add (second number)] and wait
set [value2 v] to  (awnser)
say [ithink]
say [(value1)]
say [plus]
say [(value2)]
say [is]
say [(awnser)]
then i did all the other when i recive stuff and my kitty thinks all the things i ask it are zero

I don't know. I would do:

when gf clicked
ask [What operation would you like to use? +, -, *, /] and wait
if <(answer) = [+]>
   set [operation v] to [+]
   broadcast [next v]
end
if <(answer) = [-]>
   set [operation v] to [-]
   broadcast [next v]
end
if <(answer) = [*]>
   set [operation v] to [*]
   broadcast [next v]
end
if <(answer) = [/]>
   set [operation v] to [/]
   broadcast [next v]
end
when I receive [next v]
ask [First value?] and wait
set [first value v] to (answer)
ask [Second value?] and wait
set [second value v] to (answer)
if <(operation) = [+]>
   set [answer v] to ((first value) + (second value))
end
if <(operation) = [-]>
   set [answer v] to ((first value) - (second value))
end
if <(operation) = [*]>
   set [answer v] to ((first value) * (second value))
end
if <(operation) = [/]>
   set [answer v] to ((first value) / (second value))
end

Last edited by curiouscrab (2012-08-23 22:08:18)


http://i50.tinypic.com/dopbtw.png

Offline

 

#3 2012-08-25 21:09:08

Flycon2002
Scratcher
Registered: 2011-03-26
Posts: 21

Re: Calculator script gone wrong!

yay

Offline

 

#4 2012-09-30 09:56:53

krzysiogawl01
Scratcher
Registered: 2012-05-02
Posts: 13

Re: Calculator script gone wrong!

Flycon2002 wrote:

Is this correct? if not please help!
I am ten.

when gf clicked
ask [what is your operator? +,-,*,and /] and wait
if < (awnser) = [+]>
set [awnser v] to < (value1) + (value2)>
end
broadcast [add v]
if < (awnser) = [-]>
set [awnser v] to < (value1) - (value2)>
broadcast [sub v]
end
if < (awnser) = [*]>
set [awnser v] to < (value1) * (value2)>
broadcast [multi v]
end
if < (awnser) = [/]>
set [awnser v] to < (value1) / (value2)>
broadcast [div v]
end

When I recive [add v]
ask [what do you want to add (first number)] and wait
set [value1 v] to (awnser)
ask [what do you want to add (second number)] and wait
set [value2 v] to  (awnser)
say [ithink]
say [(value1)]
say [plus]
say [(value2)]
say [is]
say [(awnser)]
then i did all the other when i recive stuff and my kitty thinks all the things i ask it are zero

I think you might use

when gf clicked
ask [first number] and wait
set [value1 v] to (answer)
ask [second number] and wait
set [value2 v] to  (answer)
ask [what is your operator? +,-,*,and /] and wait
if < (answer) = [+]>
set [awnser v] to <(value1) + (value2)>
end
if < (answer) = [-]>
set [awnser v] to <(value1) - (value2)>
end
if < (answer) = [*]>
set [awnser v] to <(value1) * (value2)>
end
if < (answer) = [/]>
set [awnser v] to <(value1) / (value2)>
end
say [I think]
say (value1)
say (answer)
say (value2)
say [is]
say (awnser)
stop script


Don't know how to make a 0s1s stopwatch?
http://scratch.mit.edu/static/icons/buddy/1350608_med.png

Offline

 

#5 2012-09-30 11:39:40

TheSupremeOverLord
Scratcher
Registered: 2012-09-29
Posts: 100+

Re: Calculator script gone wrong!

I found this calculator
http://scratch.mit.edu/projects/lizzyhippo/2782632


http://i1154.photobucket.com/albums/p522/lizzyhipo/MINIPIG.jpg

Offline

 

#6 2012-10-04 09:13:43

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: Calculator script gone wrong!

Currently it isn't correct. There are two ways you can correct it in.

One option is changing the order in the way krzysiogawl01 did.

The other option is to do this:


When gf clicked
ask [What is your operator? +,-,*,/] and wait
if <(answer) = [+]>
broadcast [add v]
set [answer1 v] to <(value1) + (value2)>
end
if <(answer) = [-]>
broadcast [sub v]
set [answer1 v] to <(value1) - (value2)>
end
if <(answer) = [*]>
broadcast [mult v]
set [answer1 v] to <(value1) * (value2)>
end
if <(answer) = [/]>
broadcast [div v]
set [answer1 v] to <(value1) + (value2)>
end
say <join [I think the answer is ] (answer1)>
When I receive [add v]
ask [What do you want to add? (First number)] and wait
set [value1 v] to (answer)
ask [What do you want to add? (Second number)] and wait
set [value2 v] to (answer)
stop script
etc.
---

The problem with what you did is that you were calculating the answer before you got the two values needed to calculate it.

Last edited by Smozzick (2012-10-04 09:15:15)


http://i50.tinypic.com/ded8m.png

Offline

 

Board footer