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

Username:   Password: 
 RegisterRegister   
 IF statements.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
M49913




PostPosted: Sat Jun 06, 2009 1:27 pm   Post subject: IF statements.

What is it you are trying to achieve?
I'm trying to have a online store


What is the problem you are having?
I'm having problems with "if" statements.
When the user types in 'continue' i want to be directed back to the store
when they are done, i want to be directed to the bill.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

procedure asking1
put " " : 30 ..
put "Which product number would you like to buy?" ..
get answer (1)
cls
put "How many ", product (1), " would you like to buy at the price of ", workbooks, "?"
get quantity (1)
loop
if YN (1) = "continue" then
put store
put "Would you like to continue shopping or see your bill?"
get YN (1)
exit when YN (1) = "bill"
end if
end loop
end asking1
Turing:




Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
apomb




PostPosted: Sat Jun 06, 2009 2:24 pm   Post subject: RE:IF statements.

there is a difference between "=" and "=="

maybe start there.

edit: spelling
Kharybdis




PostPosted: Sat Jun 06, 2009 3:52 pm   Post subject: Re: IF statements.

Turing:
procedure asking1
    put " " : 30 ..
    put "Which product number would you like to buy?" ..
    get answer (1)
    cls
    put "How many ", product (1), " would you like to buy at the price of ", workbooks, "?"
    get quantity (1)
    loop
        if YN (1) = "continue" then
put store
            put "Would you like to continue shopping or see your bill?"
            get YN (1)
            exit when YN (1) = "bill"
        end if
    end loop
end asking1


First, please use syntax tags. When you make code, type syntax="turing" and end with /syntax with your code inbetween.
Both of those should be surrounded by [ ]
Second, you would do well to post the code that directly relates to this procedure. Things such as YN are not defined by this procedure (and it's good practice to do so), and thus this is of absolutely no help when trying to solve your problem.
Third, what is the purpose of the line 'put store'? Is it a function...? And, in general, your loop should be restructured into the following (if what you're doing is correct in terms of all of your other code) :

Turing:
loop
    put "Would you like to continue shopping or see your bill?"
    get YN (1)
    if YN (1) = "continue" then
        store %This i would assume to be a procedure.
        %'put store' makes no sense.. unless its a function.. but then ..
    elsif YN (1) = "bill" then
        exit
    end if
end loop
andrew.




PostPosted: Sat Jun 06, 2009 6:40 pm   Post subject: RE:IF statements.

I'm guessing that YN is yes or no, so whether the person types in "y", "n", or "fhdjdhfkjf", it will never equals "continue" or "bill". Instead check to see if it equals "y" or "n" because by putting (1) after, you're only checking the first letter.

Here is an example using the code posted by Kharybdis:
Turing:
loop
    put "Would you like to continue shopping or see your bill?"
    get YN (1)
    if YN (1) = "y" then
        store %This i would assume to be a procedure.
        %'put store' makes no sense.. unless its a function.. but then ..
    elsif YN (1) = "n" then
        exit
    end if
end loop
apomb




PostPosted: Sat Jun 06, 2009 7:01 pm   Post subject: RE:IF statements.

the error is in the use of "=" and not "=="...

by using "=" it will set yn(1) to y every time, then set yn(1) to n after its done executing store right away. there is no actual choise going on.
andrew.




PostPosted: Sat Jun 06, 2009 7:08 pm   Post subject: RE:IF statements.

Apomb, it's Turing. Using "==" in an if statement is illegal in Turing. Only "=" is accepted so he is doing it right. The problem is that he's looking at the first character of a string and he's comparing it to a full string. Obviously "y" will never equal "bill".
apomb




PostPosted: Sat Jun 06, 2009 7:09 pm   Post subject: RE:IF statements.

oh... dang, sorry. its been too long.

you're right. my bad.
Kharybdis




PostPosted: Sat Jun 06, 2009 7:11 pm   Post subject: Re: RE:IF statements.

apomb @ Sat Jun 06, 2009 7:01 pm wrote:
the error is in the use of "=" and not "=="...

by using "=" it will set yn(1) to y every time, then set yn(1) to n after its done executing store right away. there is no actual choise going on.


you are confusing a cousin of c++ with turing, mon ami. the assignment statement in turing is :=, not =, while the equal statement is =, not ==

and andrew, when i looked at YN(1), i thought he was going into an array, although i had a funny feeling that he wasn't ... HAH. its the first letter of the word! :/
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Sat Jun 06, 2009 9:18 pm   Post subject: RE:IF statements.

Well seeing that he was having problems with if statements, I assumed that he wasn't trying arrays.
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  [ 9 Posts ]
Jump to:   


Style:  
Search: