
-----------------------------------
battleroyale
Mon Apr 11, 2005 7:54 pm

if statement (i got no answers from tutuorial section...
-----------------------------------
i have to repost this here....

hello everyone....I AM A NOOB AT TURING....im trying to master (or at least understand the basics) of turing for my computer science class....im writing a simple "chat" program that you input names, dates, ages, etc and its like a chat room. Now iwant to do some yes and no questions with different answers...can anyone help me on how to put if statements in..like 
if ...this 
then ....that 
end if 
or 
if ...that 
then ...this 
end if 

w/e....thanks alot 

BR

-----------------------------------
Vertico
Mon Apr 11, 2005 8:07 pm


-----------------------------------
Im not sure what u mean so ill just give u a very easy example.



var name : string 

get name:*                    %%gets the name from user.

if name = "bob" then        %%If the name is bob then it will say the line below this
put "hello ", name

elsif name = "dude" then       %%if his name is dude then it will say this
put"Whats up ", name

else
put"I dont know anyone named ", name       %%if its something else it will say this

end if



-----------------------------------
battleroyale
Mon Apr 11, 2005 8:29 pm


-----------------------------------
that accually helped alot...but what if the question was like a yes or no...and if you answered something else it wouldnt work...like you need to ask them again..you loop it right? but when they answer in yes or no...how do you get out of the loop? 

Where do you put the loop and end loop?

var ques1:string
put "Do you think halo sucks? ", "yes or no?"
get ques1:* 

if ques1 = "yes" then 
put "good job...cs rules"

elsif ques1 = "no" then
put "Why do you like bad games for?"

else 
put "you have to answer yes or no"
end if

-----------------------------------
marshymell0
Mon Apr 11, 2005 8:47 pm


-----------------------------------
if you want to ask the same question over and over again, put loop at the beginning after you declare the variable. THerefore, you get 
var ques1 : string
loop
    put "Do you think halo sucks? ", "yes or no?"
    get ques1 : *

    if ques1 = "yes" then
        put "good job...cs rules"

    elsif ques1 = "no" then
        put "Why do you like bad games for?"

    else
        put "you have to answer yes or no"
    end if
end loop
If you want to exit the loop, then you need an exit when statement, for example, if you want the program to end after you answer yes, you put 

exit when ques1 = "yes"  after your if statement and before your end loop statement

-----------------------------------
Tony
Tue Apr 12, 2005 8:43 am


-----------------------------------
exit when condition is equivalent of if  then exit

Anyways, battleroyale -- if you don't know how to use if statement, don't try to make a chat program. There are too many things that you're not familiar with yet.

-----------------------------------
StarGateSG-1
Tue Apr 12, 2005 10:59 am


-----------------------------------
You shouldn't even be using If statments for a chat program you shoudl be learning case, process, procedure, module, serevrs, clients. Until you knwo all that stuff go back to turing for begineer's. WNating to make really nice programs is just as bad as wanting to make hacks. You people need to understand that your are intaneous a programing genious they are very few and far between.

-----------------------------------
Martin
Tue Apr 12, 2005 12:57 pm


-----------------------------------
if and case are the same thing in turing.

-----------------------------------
battleroyale
Tue Apr 12, 2005 7:49 pm


-----------------------------------
yo..no need to yell at me...i now i am noob...by chat program i meant like you are talking to someone...like if they ask you a question and you answer yes or no...like that....omg...people are so mean. 

Ok i have another question...stupid maybe...for my computer science homework...my teacher gave me like 10 questions..i finished them all (it was simple problems where user puts in numbers like age, money, etc. and you calculate them) What i want to do is first put a question like "WHich question would you like to see?" and then you got the questions listed. I wrote that and put the 

if ques1="8" (example) then........

what do i do....cuz for c++ my friend told me you could tell it to "GO TO" a specific line and run in from there. Is there something like that too? or do i have to just put in the entire question 8 after then? Thanks again for helping and not flaming...

BR

-----------------------------------
Tony
Tue Apr 12, 2005 8:51 pm


-----------------------------------
you can't go to a specific line -- that's not proper programming

-----------------------------------
[Gandalf]
Tue Apr 12, 2005 11:20 pm


-----------------------------------
That's BASIC (old stuff) what you have to understand is that you can do everything that you would have done on the line you GOTO'ed in an if statement or something of the sort.

BASIC:
 
10 Input "Name?"; name
20 If name = gandalf then goto 40
30 BLAH BLAH
40 print "hi"

(blah, something like that, its been a while...)

Turing:

var name : string
put "Name?"
get name
if name = "gandalf" then
    put "hi"
else
    put "nothing"
end if

something like that can be used for much larger programs too - just experiment and youll get the concept soon enough!  :) 

btw, Halo AND CS both suck so your program is flaud.

-----------------------------------
battleroyale
Wed Apr 13, 2005 1:34 pm


-----------------------------------
i knew that already...but you see...i have 10 different types of programs and i want to make a "menu" for it....what is the easiest way to make one.

the programs are like 5-10 lines long (for school) and i want to make a menu....so like i ask. "which question would you like to see". THen i list the numbers....and the user put like 1 or w/e. then it jumps to that...

-----------------------------------
jamonathin
Wed Apr 13, 2005 2:04 pm


-----------------------------------
The best idea I saw was from andy.  Compile each program (run [not f1], then generate stand-alone, then ok)  and have a new program named 'menu' run each of your questions.
use Sys.Exec to open the programs up.
If that's too complicated, then make one program that includes every question in it.

-----------------------------------
Martin
Wed Apr 13, 2005 2:29 pm


-----------------------------------

proc Tetris
     ...your code for tetris goes here...
end Tetris

proc Snake
     ...your code for snake goes here...
end Snake

var choice : char (1) %not sure about the syntax on this one...
loop
     put "1. Play Tetris"
     put "2. Play Snake"
     put "3. Quit"
     getch (choice)
     if choice = "1" then
           Tetris
     elsif choice = "2" then
           Snake
     elsif choice = "3" then
            exit
     end if
end loop

-----------------------------------
battleroyale
Wed Apr 13, 2005 5:30 pm


-----------------------------------
martin you just saved me sooo much time
this is what i did first for my "menu"
var ques1:string
loop
put "Which question to you want to see?"
put "1. 2. 3. 4. 5. 6. 7. 8. 9. 10."
get ques1:*
cls
if ques1= "1" then  
    
    
       
        const pi:=3.14159
        var rad:real
loop    
        put "What is the radius of the circle?"
        get rad
        put "The area of the circle is ", pi*rad**2
        delay (2000)
        cls
        
        var yorn:string
        put "Are you finished with the question? y or n"
        get yorn
        cls
        exit when yorn="y" 
        cls
 
    end loop

elsif ques1="2" then 
    
    
        var fname:string
loop        
        put "What is your name?"
        get fname
        cls
        put "Hello ",fname
        delay (2000)
        cls
        
        var yorn:string
        put "Are you finished with the question? y or n"
        get yorn
        cls
        exit when yorn="y" 
    end loop            %keeps on going
        cls

as you can see...very confusing because it goes all the way up to ten.
but after the proc and end blah it got so much simplier.
Thanks alot. Now to learn how to do the infamous GUI. 
any links will be appreciated.

[/code]

-----------------------------------
Hikaru79
Wed Apr 13, 2005 9:54 pm


-----------------------------------

Thanks alot. Now to learn how to do the infamous GUI. 
any links will be appreciated.



No, no, please don't. I don't want to come accross as mean as you seem to have interpreted some other comments. But the Turing GUI is one of the most convoluted and confusing modules in Turing. Please, before you attempt it, get some more basics under your belt. I'm not insulting your intelligence, just that going from if statements to GUI is a bit of a leap. Ask more questions here =) Work your way up, baby steps.

-----------------------------------
battleroyale
Thu Apr 14, 2005 1:07 pm


-----------------------------------
so what shuld i learn now?

-----------------------------------
Martin
Thu Apr 14, 2005 1:11 pm


-----------------------------------
How to use procedures and functions. After that, learn about classes, and finally learn about pointers.

-----------------------------------
battleroyale
Thu Apr 14, 2005 5:37 pm


-----------------------------------
alright...procedures dont...i actually got the basics of GUI.  :D . 

now im trying to make a lottery game and first problem i got is how to make it so that the numbers you can choose are only between 1-10

i tried putting var number : int:=(1,69) but that didnt work...what should i do?

 :o

ALso how do you make it so that if statements can contain more then one =

like if blah="a" or "b" or "c"
cuz that doesnt work...but it makes sence though....

-----------------------------------
Martin
Thu Apr 14, 2005 6:20 pm


-----------------------------------
Look up Rand.Int

-----------------------------------
battleroyale
Thu Apr 14, 2005 9:06 pm


-----------------------------------
i understand random number already...i just don tknow how to put constraints on the numbers you can choose

-----------------------------------
jamonathin
Fri Apr 15, 2005 7:46 am


-----------------------------------
You cant put:If whatever = "this" or "that" then
You need to put whatever again.
If whatever = "this" or whatever = "that" then

-----------------------------------
Martin
Fri Apr 15, 2005 8:12 am


-----------------------------------
This is because if statements function as follows

if [statement 1] = true or [statement 2] = true or ... then

So what your if statement 'if blah="a" or "b" or "c" ' translates to is:

if (blah = "a") = true or ('b' = true) or ('c' = true) then ..

as you see, although your statement makes sense in english, it doesn't make much sense in Turing.

-----------------------------------
battleroyale
Fri Apr 15, 2005 2:02 pm


-----------------------------------
ok thanks.....i got it....

NOW lol...how do you make a counter? i cant find the thread...someone give me the link

-----------------------------------
[Gandalf]
Fri Apr 15, 2005 5:26 pm


-----------------------------------
If whatever = "this" or whatever = "that" then
hehehe, I didn't know that, I just used case statements - thanks! :D

What do you mean by counter?

var count : int := 1
loop
put count
delay(5)
count += 1
cls
end loop

or

for i : 1 .. 100
cls
put i
delay (10)
end for

both of those can be considered counters?

*edit* grr, thats two of those kinds of posts I've had to do in the same topic :doh:

-----------------------------------
acidburn90
Wed Apr 20, 2005 9:47 pm


-----------------------------------
yeh thats true... ive been working on turing for a long time (7 months) and i still sometimes have troubles with the GUI...
also one more thing...
someone in this forums did some pretty bad programming...
its bad programming to put

its exit when answer:= "quit"
just making u didnt get i9t mixed for anything major[/quote]
