Posted: Sun Mar 06, 2005 12:47 pm Post subject: Question game
hello all, I'm new here and have a question regarding turing. I want to create a question game using turing. A question is asked, and then 4 multiple choice answers are given. At the end I want it to sya how many oyu got right, and the percentage. Then ask if you want to play again. IF so, then the score would have to be reset back to 0. Can any one help me??
thanx
Sponsor Sponsor
person
Posted: Sun Mar 06, 2005 1:43 pm Post subject: (No subject)
look at if statements
Tony
Posted: Sun Mar 06, 2005 2:33 pm Post subject: (No subject)
Turing:
var score:int:=0 loop %games here
if playAgain then
score :=0 else exit endif endloop
SwAnK
Posted: Sun Mar 06, 2005 5:07 pm Post subject: (No subject)
Thanx, that will really help. My main problem though is asking a multiple choice question and if they pick the right letter, then it adds 1 to the count and contiues on. and if their wrong it continues on anwyas until all the questions are answered. Would that work with an if statment?
if answer = "a" then count +=1??
I was thinking of making a boolean type since they are either wrong or write with the letter they chose.
thanx again
person
Posted: Sun Mar 06, 2005 6:23 pm Post subject: (No subject)
yes it will work
Cervantes
Posted: Sun Mar 06, 2005 6:57 pm Post subject: (No subject)
If there are going to be lots of questions or if you want to make the questions easily customizable, and you want to cut down the # of lines your program is, you should look into getting information from files. Check the tutorial section, search for the one by Dan.
SwAnK
Posted: Mon Mar 07, 2005 10:45 pm Post subject: (No subject)
I cant find that turtorial, but thanx anyways, Ive written the game out, and it says your score and everything. Now i would like to add something else to it. How would you ( in one consecutive run of the prgogram, without closing it) be able to store like the last 5 scores, so it would come up with something simple like, "previous scores of this game were 3, 5, 4, 1, 2? would it be along the lines of before the score gets erased and reset back to 0, it is stored in another variable alreayd declared? And would you have to create like 5 of these storage variables, or is there some simpliar other way to do it????
jamonathin
Posted: Tue Mar 08, 2005 10:05 am Post subject: (No subject)
if your talking about a high score, go look in tutorials
Sponsor Sponsor
Token
Posted: Tue Mar 08, 2005 11:59 am Post subject: (No subject)
you could use two arrays, use one to keep the name and another to keep the score it would look somthing like this
code:
var score : array 1 .. 5 of int
var name : array 1 .. 5 of string
var game : int := 0
var finalscore : int
loop
game += 1%%to count which game it is on
put "Enter Your Name: " ..
get name (game)
%%game goes here
finalscore := Rand.Int (50, 100)%%to simulate the scores
score (game) := finalscore
exit when game = 5
end loop
for i : 1 .. 5
put name (i), ": ", score (i)
end for
the thing is it looks a little messy when you output the scores, you might want to align it in columns or somthing and also you could sort the arrays to make it like a real top scores list. another thing u might want it to do is display the scores at the end of each game, to do that move the score part inside the loop and...
change this
code:
for i : 1 .. 5
put name (i), ": ", score (i)
end for
To this
code:
for i : 1 .. game
put name (i), ": ", score (i)
end for
-Enjoy
person
Posted: Tue Mar 08, 2005 3:29 pm Post subject: (No subject)
file IO
Token
Posted: Tue Mar 08, 2005 3:36 pm Post subject: (No subject)
Quote:
file IO
it could be done through file IO but he said he just wanted it so that it would work through the loop so a array would suffice. in case you would like to create a new file to hold the scores heres a link
Posted: Tue Mar 08, 2005 8:26 pm Post subject: (No subject)
Token wrote:
you could use two arrays, use one to keep the name and another to keep the score it would look somthing like this
Better yet, use a flexible array of a record. That way, you an array of 'objects' (contestants, in this case) and their name and score is stored.
Turing:
var player :flexiblearray1.. 0of record
name :string
score :int endrecord
P.S. I just choked on a mouthful of chile while typing. I had an explosive cough, and couldn't get my hands up in time. Needless to say, my keybaord doesn't look so white anymore.
Token
Posted: Tue Mar 08, 2005 8:30 pm Post subject: (No subject)
lol i'm sorry for your keyboard Cervantes and thanks a lot for your help, i checked it out and i understand what you mean now
SwAnK
Posted: Tue Mar 08, 2005 8:38 pm Post subject: (No subject)
AHAHA, yes that is too bad for your keyboard. And thank you all for your help. I have completed the game, it works perfectly, thank you.
Could you also explain to me about the flexible array? it sounds interesting.
Token
Posted: Wed Mar 09, 2005 3:48 pm Post subject: (No subject)
okay a providing that you already know what an array is, well a flexable array is just a 2-d array (an array within an array) that has 2 different types , string and integer for example, but Cervantes would probibly be able to tell you about it better than me