
-----------------------------------
M49913
Sat Jun 06, 2009 1:27 pm

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




Please specify what version of Turing you are using


-----------------------------------
apomb
Sat Jun 06, 2009 2:24 pm

RE:IF statements.
-----------------------------------
there is a difference between "=" and "=="

maybe start there.

edit: spelling

-----------------------------------
Kharybdis
Sat Jun 06, 2009 3:52 pm

Re: IF statements.
-----------------------------------
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 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.
Sat Jun 06, 2009 6:40 pm

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:
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
Sat Jun 06, 2009 7:01 pm

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.
Sat Jun 06, 2009 7:08 pm

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
Sat Jun 06, 2009 7:09 pm

RE:IF statements.
-----------------------------------
oh... dang, sorry. its been too long. 

you're right. my bad.

-----------------------------------
Kharybdis
Sat Jun 06, 2009 7:11 pm

Re: 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.

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! :/

-----------------------------------
andrew.
Sat Jun 06, 2009 9:18 pm

RE:IF statements.
-----------------------------------
Well seeing that he was having problems with if statements, I assumed that he wasn't trying arrays.
