Computer Science Canada

How to make A question and answer game?

Author:  bc123 [ Thu Oct 15, 2009 2:52 pm ]
Post subject:  How to make A question and answer game?

Hey i wanted to do something when i make it say What is my name and then some one has to answer corectly to say corect and if wrong then say incorrect.

I am totaly new to turing im starting to learn in school and i want to atleast kno this. All i kno is like

% blablabla is comments
and put and get but im not too sure like how to use them like with int and everything plzz help! and 1 more thing i wanted to kno how to get back to main like screen so i dont have to close the turing thing and click run again. TY Very Happy
also i dont want some 1 to give me the code and say here you go did it for you... if you can plz try to explain like i tried to do

%Brandon
% october 15 2009
var 1 = int
put "Hello! "
put "Answer the questions corectly "
get

im totaly lost and dont think this makes sense whatsoever so plz help!

Author:  andrew. [ Thu Oct 15, 2009 3:06 pm ]
Post subject:  RE:How to make A question and answer game?

Okay, well here is a summary of different functions:
put - you can write stuff to the screen
get - you can get input from the user (this includes strings, ints, etc.)
int - an integer type. It holds only non-decimal numbers
loop - you can have certain parts of your code loop around until some kind of condition is met (in your case, they guess the right age)

If you need more help with the functions, look them up in the Turing help (press F10 in Turing) and then write out (in plain English) every step it will take to do this. Then you can easily turn that into Turing code.

Author:  bc123 [ Thu Oct 15, 2009 3:10 pm ]
Post subject:  RE:How to make A question and answer game?

still confused :S sorry

Author:  S_Grimm [ Thu Oct 15, 2009 3:13 pm ]
Post subject:  RE:How to make A question and answer game?

if (statement)
else (statement)

those two will enable you to make a Q&A game

Author:  bc123 [ Thu Oct 15, 2009 3:17 pm ]
Post subject:  RE:How to make A question and answer game?

what exactly you mean by statements? var?

Author:  S_Grimm [ Thu Oct 15, 2009 3:38 pm ]
Post subject:  Re: How to make A question and answer game?

for example
Turing:

put "Input a number"
int i
get i
if (i = 1) then
put "you inputed 1"
end if
if (i = 2) then
...

Author:  ecookman [ Thu Oct 15, 2009 3:46 pm ]
Post subject:  Re: How to make A question and answer game?

statements are lines...in lack of a better term...do something or declare something

var creates a variable
anything after var is the variable the : says that that variable is this...either a string (text) or Boolean (true, false 1, 0), or a integer.


Basically you need a bunch of if, else, and get statements.

Here is a example. Please tell me how it works and fill in the blanks (remove the _____). (comment the code)


Turing:

locate (1,15)
put "Q and A game"
var n : string


locate (3, 5)
put "SAY MY NAME"
get n

if n = "_____" then
put ___________
_______
put "wtf bbq...no"
end _____


Author:  bc123 [ Thu Oct 15, 2009 3:51 pm ]
Post subject:  RE:How to make A question and answer game?

TY SO MUCH wut does locate do?

Author:  ecookman [ Thu Oct 15, 2009 3:53 pm ]
Post subject:  Re: RE:How to make A question and answer game?

bc123 @ Thu Oct 15, 2009 3:51 pm wrote:
TY SO MUCH wut does locate do?


notice how the text isn't at thr right side of the page and a little down

locate tells the text where to be put


also could you tell me how the code works so you are not copying it.

Author:  bc123 [ Thu Oct 15, 2009 3:58 pm ]
Post subject:  RE:How to make A question and answer game?

ok
i re typed it

put "Question and Answer Game"
var n : string


put "What is my name?"
get n
if n = "brandon" then
put "correct"
else
put "wrong"
end if

put is puting out like a comment but visual (no code_

the variable im not too sure about also nto too sure about the string

from what i understand get n is getting the variable and saying if n = my name theh (type correct of w/e) else meaning if it is sumthing else type "error" and the end if is ending the if statement

Author:  bc123 [ Thu Oct 15, 2009 4:00 pm ]
Post subject:  RE:How to make A question and answer game?

wait does the string replace puting int?

Author:  S_Grimm [ Thu Oct 15, 2009 4:01 pm ]
Post subject:  RE:How to make A question and answer game?

Turing:
if (n = "brandon") then


yes, string replaces int

Author:  bc123 [ Thu Oct 15, 2009 4:03 pm ]
Post subject:  Re: How to make A question and answer game?

AV @ Thu Oct 15, 2009 3:38 pm wrote:
for example
Turing:

put "Input a number"
int i
get i
if (i = 1) then
put "you inputed 1"
end if
if (i = 2) then
...

i couldnt get this to work it sayd 2 errors

Author:  S_Grimm [ Thu Oct 15, 2009 4:05 pm ]
Post subject:  RE:How to make A question and answer game?

well, I havent coded turing in almost forever so i forgot the following:

code:

var i : int


not
code:

int i


also that is not a complete program.

remove the
code:

if (i = 2) then
...

Author:  bc123 [ Thu Oct 15, 2009 4:06 pm ]
Post subject:  RE:How to make A question and answer game?

ok i amd goin to make a quick game hopefully it will workout and ill send to you if youd like but theres gunna be about 20 questions XD or 15

Author:  ecookman [ Thu Oct 15, 2009 4:09 pm ]
Post subject:  RE:How to make A question and answer game?

alright

After var you can put anything you want as if it is not a turing function like get or put.

what follows var is something that you can control what it is.

I could say
var (says a vairible is being made) chips (name of the variable) : string (strings are text int is numbers)

chips := 1 (this says that the variable chips is equal to one)

put chips (this says print the variable to the screen which all you will see is a 1

so that looks like
code:

var chips : int
chips:=1
put chips

the get statement after a line pauses the program and waits for user input. after you hit enter, what you typed is saved ot the variable for later use (the variable is saved untill you close the run window)

Author:  bc123 [ Thu Oct 15, 2009 5:06 pm ]
Post subject:  Re: How to make A question and answer game?

download the notpad file and paste into turing
hope i posted it right

Author:  bc123 [ Thu Oct 15, 2009 5:12 pm ]
Post subject:  Re: RE:How to make A question and answer game?

ecookman @ Thu Oct 15, 2009 4:09 pm wrote:
alright

After var you can put anything you want as if it is not a turing function like get or put.

what follows var is something that you can control what it is.

I could say
var (says a vairible is being made) chips (name of the variable) : string (strings are text int is numbers)

chips := 1 (this says that the variable chips is equal to one)

put chips (this says print the variable to the screen which all you will see is a 1

so that looks like
code:

var chips : int
chips:=1
put chips

the get statement after a line pauses the program and waits for user input. after you hit enter, what you typed is saved ot the variable for later use (the variable is saved untill you close the run window)
oooo i see ty im starting to catch on. very helpful! um do u think you have an idea of how i would make this

my teacher wants us to make a stat thing for any sport player, i dhose sidney crosby(not sure why)
then he wants use to enter goals assists total points and then it will all display at the end

so he wants it to say

number of goals
(then i enter it here)
number of assists
(enter it here)
total points:
(enter here)
process
sidney crosby ##goals, ## assists ## points

i have no idea on what to do Rolling Eyes

Author:  ecookman [ Thu Oct 15, 2009 5:39 pm ]
Post subject:  RE:How to make A question and answer game?

step one...make your variables (these are numbers hint hint)

you would use the put statement to ask the questions

Then a following get statement

Then, if he hasn't told you how to do this, it isn't intuitive.

if you put a variable after the put statement without quotes. the variable will display what it is holding. look at the code i made with chips...look at the put statement. Notice in turing how chips is blue...the same color as the variable. Also when you run the program you see a 1 not chips???

code:

var chips : int
chips := 1
put chips


what you will want to do is display the variables between text

put "he has", goalVar, "goals", assistVar, "assists", pointsVar, "points"


goalVar, assistVar and pointsVar are all variables like chips in this case. When displaying a variable or anything else within text you need to put a comma before and after anything that isn't in quotes. (that is just so turing knows what it is) If you don't you will get a error. There is a long explanation behind it....but that is the general reason.

Author:  bc123 [ Thu Oct 15, 2009 5:44 pm ]
Post subject:  Re: RE:How to make A question and answer game?

ecookman @ Thu Oct 15, 2009 5:39 pm wrote:
step one...make your variables (these are numbers hint hint)

you would use the put statement to ask the questions

Then a following get statement

Then, if he hasn't told you how to do this, it isn't intuitive.

if you put a variable after the put statement without quotes. the variable will display what it is holding. look at the code i made with chips...look at the put statement. Notice in turing how chips is blue...the same color as the variable. Also when you run the program you see a 1 not chips???

code:

var chips : int
chips := 1
put chips


what you will want to do is display the variables between text

put "he has", goalVar, "goals", assistVar, "assists", pointsVar, "points"


goalVar, assistVar and pointsVar are all variables like chips in this case. When displaying a variable or anything else within text you need to put a comma before and after anything that isn't in quotes. (that is just so turing knows what it is) If you don't you will get a error. There is a long explanation behind it....but that is the general reason.

how is this
isnt like what u said but i guess it kinda works
locate (1,20)
put "Sidney Crosby's 2009-2010 current stats"
put "Please type in Sidney Crosby and hit enter"
put "please use proper spelling(use UNDERSCORE as space and capitals)"
var i : string
get i
if i = "Sidney_Crosby" then

put "Number: 87"
put "Height: 5' 11"
put "Weight: 200"
put "Shoots: Left"
put "Born: Aug 7, 1987 (Age 22) "
put "Birthplace: Cole Harbour, NS, Canada "
put "Goals:4"
put "Assists:1"
put "+/-:2"
else
put "error"
end if

Author:  ecookman [ Thu Oct 15, 2009 5:52 pm ]
Post subject:  RE:How to make A question and answer game?

good job. Thats how you code!



Just 2 things.


you can have spaces in a get statement...meaning the _ is unnecessary you can use a space.


also

If you want....you don't need the else statement and error. The else statement waits form anything that happens that doesn't follow the rules set above.
(your if statement)
you can just remove it. BUT if you want to keep it try to make the put statement more decriptive. such as.

put "You have failed to input the wrong text. Please restart the program and this time read the directions.)

Author:  bc123 [ Thu Oct 15, 2009 5:57 pm ]
Post subject:  RE:How to make A question and answer game?

good idea . and how do you write your code in code box. and when i try put a space in if statement i get an error no matter what.

Author:  bc123 [ Thu Oct 15, 2009 5:59 pm ]
Post subject:  RE:How to make A question and answer game?

oh and another thing i realized i dunno if you downloaded my trivia thing but even if i enter the wrong answer is still asks next question? would i somehow need to enter a statements on each 1 saying end if its wrong?

Author:  ecookman [ Thu Oct 15, 2009 6:02 pm ]
Post subject:  Re: RE:How to make A question and answer game?

bc123 @ Thu Oct 15, 2009 5:57 pm wrote:
good idea . and how do you write your code in code box. and when i try put a space in if statement i get an error no matter what.


sorry mixing up my languages.

you can use either (code) put code here (/code) (use square brackets)


or below the img button click More Tags and then syntax and between "" put Turing and then when you are done putting your code put [/syntax] or click close tags

Author:  bc123 [ Thu Oct 15, 2009 6:04 pm ]
Post subject:  Re: How to make A question and answer game?

code:
locate (1, 15)
put "Question and Answer Game"
locate (5, 15)
put "Made by: bc123"



put "All answers will have no capitals and no spaces"
var n : string


put "which of the following is incorrect?"
put "a  I love bacon"
put "b  I hate school"
put "c  I am newbie at coding"
put "d  compsci.ca is useless"
get n
if n = "d" then
    put "correct"
else
    put "wrong"
end if

put "Question 2"
var a : string


put "what is this program called?"
get a
if a = "turing" then
    put "correct"
else
    put "wrong"
end if

put "Question 3"
var b : string


put "we are in the year...?"
get b
if b = "2009" then
    put "correct"
else
    put "wrong"
end if


put "Question 4"
var c : string


put "What is the username of the creator of this game?"
get c
if c = "bc123" then
    put "correct"
else
    put "wrong"
end if


put "Question 5"
var d : string


put "turing was named after who?"
get d
if d = "alanturing" then
    put "correct"
else
    put "wrong"
end if


put "Question 6"
var e : string


put "what color is the sky?"
get e
if e = "blue" then
    put "correct"
else
    put "wrong"
end if


put "Question 7"
var f : string


put "Infants have more or less bones then adults?"
get f
if f = "more" then
    put "correct"
else
    put "wrong"
end if


put "Question 8"
var g : string


put "how much oceans are in the world?"
get g
if g = "4" then
    put "correct"
else
    put "wrong"
end if


put "Question 9"
var h : string


put "What is the tallest mammal on the planet?"
get h
if h = "giraffe" then
    put "correct"
else
    put "wrong"
end if


put "Question 10"
var i : string


put "what mammal is the longest lived?"
get i
if i = "human" then
    put "correct"
else
    put "wrong"
end if


put "Question 11"
var j : string


put "what is the largest continent on earth?"
get j
if j = "asia" then
    put "correct"
else
    put "wrong"
end if


put "Question 12"
var k : string


put "what percentage of the earth is covered in water?"
get k
if k = "70" then
    put "correct"
else
    put "wrong"
end if


put "Question 13"
var l : string


put "what continent has the most countries?"
get l
if l = "africa" then
    put "correct"
else
    put "wrong"
end if


put "Question 14"
var m : string


put "a baseball field is approximately what size?"
put "1"
put "2"
put "3"
put "4"
get m
if m = "2" then
    put "correct"
else
    put "wrong"
end if


put "Question 15"
var u : string


put "how many games do Major League baseball teams play during the"
put " regular season? "
put "142"
put "152"
put "162"
put "172"
get u
if u = "162" then
    put "correct"
else
    put "wrong"
end if

put "You are good at this! I hope you didnt search through code"
put "to find the answer."

put "if you would like me to add questions onto here, PM me on compsci.ca"
% Made by bc123
put "made by bc123"
put "also if you get any mroe questions please tell me to add them TY"
here is the game

Author:  bc123 [ Thu Oct 15, 2009 6:06 pm ]
Post subject:  Re: RE:How to make A question and answer game?

ecookman @ Thu Oct 15, 2009 6:02 pm wrote:
bc123 @ Thu Oct 15, 2009 5:57 pm wrote:
good idea . and how do you write your code in code box. and when i try put a space in if statement i get an error no matter what.


sorry mixing up my languages.

you can use either (code) put code here (/code) (use square brackets)


or below the img button click More Tags and then syntax and between "" put Turing and then when you are done putting your code put [/syntax] or click close tags


hey do u got xfire or msn we gcan talk through?

Author:  ecookman [ Thu Oct 15, 2009 6:13 pm ]
Post subject:  RE:How to make A question and answer game?

to stop a program use quit

.....
else
put "wrong"
quit
end if


like that.

if you want you can also close the window

first you need to make the winow by putting this at the begginnning of your program. (the first line)
var win : int := Window.Open
then a

Window.Close (win)

("graphics:700;550")
then you can do something like this
code:

....
else
put "wrong"
delay (2000) % this pauses the program for 2000 milliseconds
 Window.Close (win) % closes window
quit %quits program for you




lol that took me a while to figure that when I first did it.

Author:  ecookman [ Thu Oct 15, 2009 6:14 pm ]
Post subject:  RE:How to make A question and answer game?

and i do have xfire.... click on the xfire icon below my sig line..

add me


and ill be a while i gotta walk my dog

Author:  andrew. [ Thu Oct 15, 2009 7:59 pm ]
Post subject:  RE:How to make A question and answer game?

You shouldn't use quit. If anything, use exit in a loop. If there is no loop, you don't need quit. Turing does things in order (does it line-by-line). When there are no more lines left, it will automatically stop.

e.g.
Turing:
var name : string
put "Enter your name"
get name : *
put "So, your name is " + name + ", huh?"

After it does that last line, it will exit automatically. The window will not close though, it will say finished for the title.

Also, I hope you noticed that after I put "get name" I added a ": *". Basically, this says to get everything including spaces. Now you don't have to use underscores, people can type in the full name.

Author:  ecookman [ Thu Oct 15, 2009 8:02 pm ]
Post subject:  Re: RE:How to make A question and answer game?

andrew. @ Thu Oct 15, 2009 7:59 pm wrote:
You shouldn't use quit. If anything, use exit in a loop. If there is no loop, you don't need quit. Turing does things in order (does it line-by-line). When there are no more lines left, it will automatically stop.


he wanted it to close if someone made a mistake along the way not just at the end.

Author:  bc123 [ Thu Oct 15, 2009 8:21 pm ]
Post subject:  Re: RE:How to make A question and answer game?

andrew. @ Thu Oct 15, 2009 7:59 pm wrote:
You shouldn't use quit. If anything, use exit in a loop. If there is no loop, you don't need quit. Turing does things in order (does it line-by-line). When there are no more lines left, it will automatically stop.

e.g.
Turing:
var name : string
put "Enter your name"
get name : *
put "So, your name is " + name + ", huh?"

After it does that last line, it will exit automatically. The window will not close though, it will say finished for the title.

Also, I hope you noticed that after I put "get name" I added a ": *". Basically, this says to get everything including spaces. Now you don't have to use underscores, people can type in the full name.


ok im kinda confused? sorry like i tottaly dont mine using quit because i kno what if does XD


: