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

Username:   Password: 
 RegisterRegister   
 if/elsif help?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
qmanjr5




PostPosted: Tue Dec 01, 2009 8:12 pm   Post subject: if/elsif help?

What is it you are trying to achieve?
Fix my if/elsif


What is the problem you are having?
Can't figure it out


Describe what you have tried to solve this problem
Asked friends


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I KNOW MY CODE ISN'T THE BEST, IT'S THE FIRST THING I'VE DONE!!!!!
please don't start on me about that Sad

Turing:

%Variables
var score : int
var answer1 : int

%Procedures
procedure correct
    score += 1
    put "YAY! :) You got it right. Congratulations, your score has been increased by 1"
end correct

procedure incorrect
    score -= 1
    put "oh no :( You got it wrong. Your score has been decreased by 1"
end incorrect

%variable values
score := 0
answer1 := 2

%Main Code
put "Hello, welcome to the Turing Quiz I've made. It is a simple quiz that has no purpose at all other than for me to test my skills"
put "The questions will start easy and get progressively easy."
put "The first question."
put "What is 1 + 1?"
get answer1
if answer1 = 2 then
    correct
end if


Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Tue Dec 01, 2009 8:18 pm   Post subject: RE:if/elsif help?

Where is your elsif? And it structured:

Turing:

if condition1 then
%code1
elsif condition2 then
%code2
elsif condition3 then
%code3
else
%code that doesn't follow under the other conditions.
end if
qmanjr5




PostPosted: Tue Dec 01, 2009 8:20 pm   Post subject: RE:if/elsif help?

I'm a bit confused :'(

The answer to question 1 or answer1 is obviously 2, so how I would I code it so that if you enter 2, it'll bring up the procedure correct, and if you enter ANYTHING else, then it'll bring you to the procedure incorrect?
If you guys would be so kind, use my variables and everything, I'm usually very confused if I don't see my variables and everything.
Zren




PostPosted: Tue Dec 01, 2009 8:32 pm   Post subject: Re: RE:if/elsif help?

Zren @ Tue Dec 01, 2009 8:18 pm wrote:
Sorry, I thought your question was talking about Elsif. Your looking for the else part of conditions. Basically it runs the code if the condition in the if statement isn't true (as well as for any elsif conditions too).

Turing:

if condition then
%code
else
%anything else
end if
qmanjr5




PostPosted: Tue Dec 01, 2009 8:56 pm   Post subject: RE:if/elsif help?

So, if I put

[syntax="turing"]
if answer1 = 2 then
correct
else
incorrect
end if
[syntax]
Kharybdis




PostPosted: Tue Dec 01, 2009 9:29 pm   Post subject: RE:if/elsif help?

That's correct, gmanjr5. The else statement exists so you can take in all the possible cases for your if statement. Add elsif statements only if there's more than one condition that you're looking for.
qmanjr5




PostPosted: Wed Dec 02, 2009 12:13 pm   Post subject: RE:if/elsif help?

Thank you all, espeically khary Very Happy
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  [ 7 Posts ]
Jump to:   


Style:  
Search: