Computer Science Canada

Turing Array help! URGENT

Author:  xboxdude_6262 [ Mon Jun 15, 2015 2:22 pm ]
Post subject:  Turing Array help! URGENT

Ok so im making a game and im using arrays (you get better marks). I want it so if they get the question right they get a point, but if they get it wrong they dont. it works as in if they get it wrong they get no points, but when they do get the question correct, it gives them a point and if they get another answer correct it wont give them another point. there points will always stay at 1.

Here is my code:


var Math_q : array 1 .. 4 of string := init ("What 10 + 13?", "What 154 + 36?", "What 7 * 8?", "What 13 * 21?")
var Math_a : array 1 .. 4 of string := init ("23", "190", "56", "273")
var answer : string
var score : int := 0
var scores : int := 0

proc Mathq



for i : 1 .. upper (Math_q)
put Math_q (i)
get answer

if answer = Math_a (i) then

scores := score + 1

end if


put scores
end for

end Mathq





Mathq

Author:  DemonWasp [ Mon Jun 15, 2015 3:30 pm ]
Post subject:  RE:Turing Array help! URGENT

Well, the variable you display is scores. You assign the value of that variable with scores := score + 1. The value of score is given by var score : int := 0 .

You should try to give all of your variables and methods descriptive names. Ideally, their names wouldn't differ by a single letter (scores vs score, Mathq vs Math_q, etc). Doing so will make it easier to write correct code.

Author:  xboxdude_6262 [ Mon Jun 15, 2015 9:21 pm ]
Post subject:  RE:Turing Array help! URGENT

Hey im sorry but if you dont mind going into more detail on how to fix it that would be great. im really new with turing. this is worth 30% of my grade!

Author:  DemonWasp [ Mon Jun 15, 2015 9:23 pm ]
Post subject:  RE:Turing Array help! URGENT

Before getting your first point, you have:
score = 0
scores = 0


Once you get a point, you do:
scores := score + 1
which gives you:
score = 0
scores = 1


When you get your second point, you do:
scores := score + 1
Now, what is the value of scores? Read very very carefully.

Author:  xboxdude_6262 [ Mon Jun 15, 2015 9:29 pm ]
Post subject:  Re: Turing Array help! URGENT

1?

Author:  DemonWasp [ Mon Jun 15, 2015 9:39 pm ]
Post subject:  RE:Turing Array help! URGENT

Correct! Now do you know why "if they get another answer correct it wont give them another point" ? Can you think of a way to fix it?

Author:  xboxdude_6262 [ Mon Jun 15, 2015 9:47 pm ]
Post subject:  RE:Turing Array help! URGENT

Im sorry but ive tried working it into my code but couldn't get it. I haven't been to class in about 3 weeks due to me breaking my ankle and fracturing my leg. ive had to research most of the things ive done.

Author:  DemonWasp [ Mon Jun 15, 2015 9:54 pm ]
Post subject:  RE:Turing Array help! URGENT

I can't just give you the answer (we don't do that here). Instead, I'll ask a rhetorical question: why do you have two different variables to hold the player's score?

Author:  xboxdude_6262 [ Mon Jun 15, 2015 10:06 pm ]
Post subject:  RE:Turing Array help! URGENT

I have to var. because thats what my teacher told me to do.

Author:  DemonWasp [ Mon Jun 15, 2015 10:07 pm ]
Post subject:  RE:Turing Array help! URGENT

Ignore your teacher for a moment. If you have a variable score, and you want to increase it by one, what do you do?

Author:  xboxdude_6262 [ Mon Jun 15, 2015 10:16 pm ]
Post subject:  RE:Turing Array help! URGENT

score := score + 1?

Author:  DemonWasp [ Mon Jun 15, 2015 10:17 pm ]
Post subject:  RE:Turing Array help! URGENT

Good. Now remove the scores variable from your code entirely. Make sure you change your put statement to use just the scores variable.

Author:  xboxdude_6262 [ Mon Jun 15, 2015 10:24 pm ]
Post subject:  RE:Turing Array help! URGENT

OMG you are a life saver thank you so much!


: