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

Username:   Password: 
 RegisterRegister   
 Question game
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SwAnK




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




PostPosted: Sun Mar 06, 2005 1:43 pm   Post subject: (No subject)

look at if statements
Tony




PostPosted: 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
      end if
end loop
SwAnK




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




PostPosted: Sun Mar 06, 2005 6:23 pm   Post subject: (No subject)

yes it will work
Cervantes




PostPosted: 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. Wink
SwAnK




PostPosted: 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???? Question
jamonathin




PostPosted: Tue Mar 08, 2005 10:05 am   Post subject: (No subject)

if your talking about a high score, go look in tutorials
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: 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 Very Happy
person




PostPosted: Tue Mar 08, 2005 3:29 pm   Post subject: (No subject)

file IO
Token




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



http://www.compsci.ca/v2/viewtopic.php?t=5340#70478- Specifically for High Score lists

http://www.compsci.ca/v2/viewtopic.php?t=6818#66063- General file I/O
Cervantes




PostPosted: 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 : flexible array 1 .. 0 of
    record
        name : string
        score : int
    end record


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




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




PostPosted: 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. Very Happy

Could you also explain to me about the flexible array? it sounds interesting.
Token




PostPosted: 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
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 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: