Very basic turing help!
Author |
Message |
Koriandr
|
Posted: Mon Dec 03, 2012 8:04 pm Post subject: Very basic turing help! |
|
|
What is it you are trying to achieve?
I'm trying to create a 3 checkpoint program that will only pass you if you have "y" answered for every question.
You car must be ignition, seatbelt must be on, and your car must be neutral.
What is the problem you are having?
As of now, as long as there is one "y", you will receive a pass. I need it to fail you unless you have all 3, but I can't figure out how.
Describe what you have tried to solve this problem
I've tried making a variable for every checkpoint, but then I can't figure out how to make them all = "y" without getting an error.
Turing: |
var answer : string
put "Is your seatbelt on? (y/n)"
get answer
put "Is your key in ignition? (y/n)"
get answer
put "Is your car in neutral? (y/n)"
get answer
if answer = "y" then
put "You have passed all the checkpoints and you may now start your car."
else
put "You cannot turn on your car at the moment. Please make sure you have passed all checkpoints."
end if
|
Please specify what version of Turing you are using
4.1.2.0
Thank you, I've just started this and so far it just seems like a whole bunch of letters and numbers.. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Panphobia
|
Posted: Mon Dec 03, 2012 8:12 pm Post subject: RE:Very basic turing help! |
|
|
well you could make three differnt variables, then get answer, get answer1, get answer2, then at the if statement instead of only answer == "y", do if answer == "y" and answer1 == "y" and answer2 == "y" then (code),and by the way your if statement is wrong, you need double equals for the boolean operator |
|
|
|
|
|
Insectoid
|
Posted: Mon Dec 03, 2012 8:24 pm Post subject: RE:Very basic turing help! |
|
|
You don't even know what your error is. What happens if you enter "y y n"? |
|
|
|
|
|
Panphobia
|
Posted: Mon Dec 03, 2012 8:29 pm Post subject: RE:Very basic turing help! |
|
|
^ he has a point, because you are changing the answer variable each time you are answering the question, so it doesnt track what you have input in the first two questions, so actually the ending if is only determined by your third answer |
|
|
|
|
|
Koriandr
|
Posted: Mon Dec 03, 2012 8:35 pm Post subject: Re: RE:Very basic turing help! |
|
|
Insectoid @ Mon Dec 03, 2012 8:24 pm wrote: You don't even know what your error is. What happens if you enter "y y n"?
Before I had
Turing: |
put "Is your seatbelt on? (y/n)"
get answer a
put "Is your key in ignition? (y/n)"
get answer b
put "Is your car in neutral? (y/n)"
get answer c
if answer a,answer b,answer c = "y" then
put "You have passed all the checkpoints and you may now start your car."
else
put "You cannot turn on your car at the moment. Please make sure you have passed all checkpoints."
end if
|
Which would give me multiple syntax errors. Can you see what I was trying to do though?
If I enter y,y,n with the one I have in the OP, it says you cannot start the car. But if you go n,y,y it says you have passed :/
I'm a beginner, like, just a few days ago xD |
|
|
|
|
|
Panphobia
|
Posted: Mon Dec 03, 2012 9:10 pm Post subject: RE:Very basic turing help! |
|
|
BRO, your if is totally wrong, one equals sign gives a value to a variable, two equals signs check if a statement is true or false, so if you want to check if they are true you do if a == b then... |
|
|
|
|
|
Tony
|
Posted: Mon Dec 03, 2012 9:34 pm Post subject: Re: RE:Very basic turing help! |
|
|
Panphobia @ Mon Dec 03, 2012 9:10 pm wrote: if a == b then...
in most languages other than Turing
@OP -- you are looking to use and operator. E.g.
Turing: |
if first_answer = "yes" and second_answer = "yes" then
% do something
end if
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Koriandr
|
Posted: Mon Dec 03, 2012 9:42 pm Post subject: Re: RE:Very basic turing help! |
|
|
Tony @ Mon Dec 03, 2012 9:34 pm wrote: Panphobia @ Mon Dec 03, 2012 9:10 pm wrote: if a == b then...
in most languages other than Turing
@OP -- you are looking to use and operator. E.g.
Turing: |
if first_answer = "yes" and second_answer = "yes" then
% do something
end if
|
Thank you everyone Didn't know about and operators. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Panphobia
|
Posted: Mon Dec 03, 2012 9:42 pm Post subject: Re: RE:Very basic turing help! |
|
|
Tony @ Mon Dec 03, 2012 9:34 pm wrote: Panphobia @ Mon Dec 03, 2012 9:10 pm wrote: if a == b then...
in most languages other than Turing
@OP -- you are looking to use and operator. E.g.
Turing: |
if first_answer = "yes" and second_answer = "yes" then
% do something
end if
|
oh yea (facepalm), but I did explain the "and" operator |
|
|
|
|
|
simpletrick
|
Posted: Tue Dec 11, 2012 10:25 pm Post subject: Re: Very basic turing help! |
|
|
You could try using boolean (true/false) to determine if the answers are correct.
Shouldn't be too hard. |
|
|
|
|
|
|
|