Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing Array help! URGENT
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xboxdude_6262




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: 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.
xboxdude_6262




PostPosted: 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!
DemonWasp




PostPosted: 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.
xboxdude_6262




PostPosted: Mon Jun 15, 2015 9:29 pm   Post subject: Re: Turing Array help! URGENT

1?
DemonWasp




PostPosted: 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?
xboxdude_6262




PostPosted: 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.
DemonWasp




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
xboxdude_6262




PostPosted: 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.
DemonWasp




PostPosted: 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?
xboxdude_6262




PostPosted: Mon Jun 15, 2015 10:16 pm   Post subject: RE:Turing Array help! URGENT

score := score + 1?
DemonWasp




PostPosted: 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.
xboxdude_6262




PostPosted: Mon Jun 15, 2015 10:24 pm   Post subject: RE:Turing Array help! URGENT

OMG you are a life saver thank you so much!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: