Author |
Message |
battleroyale
|
Posted: Mon Apr 11, 2005 7:54 pm Post subject: 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Vertico
|
Posted: Mon Apr 11, 2005 8:07 pm Post subject: (No subject) |
|
|
Im not sure what u mean so ill just give u a very easy example.
code: |
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
|
Posted: Mon Apr 11, 2005 8:29 pm Post subject: (No subject) |
|
|
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
|
Posted: Mon Apr 11, 2005 8:47 pm Post subject: (No subject) |
|
|
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
code: | 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
code: | exit when ques1 = "yes" | after your if statement and before your end loop statement |
|
|
|
|
|
Tony
|
Posted: Tue Apr 12, 2005 8:43 am Post subject: (No subject) |
|
|
exit when condition[i] is equivalent of if [i]condition 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
|
Posted: Tue Apr 12, 2005 10:59 am Post subject: (No subject) |
|
|
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
|
Posted: Tue Apr 12, 2005 12:57 pm Post subject: (No subject) |
|
|
if and case are the same thing in turing. |
|
|
|
|
|
battleroyale
|
Posted: Tue Apr 12, 2005 7:49 pm Post subject: (No subject) |
|
|
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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Tue Apr 12, 2005 8:51 pm Post subject: (No subject) |
|
|
you can't go to a specific line -- that's not proper programming |
|
|
|
|
|
[Gandalf]
|
Posted: Tue Apr 12, 2005 11:20 pm Post subject: (No subject) |
|
|
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
|
Posted: Wed Apr 13, 2005 1:34 pm Post subject: (No subject) |
|
|
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
|
Posted: Wed Apr 13, 2005 2:04 pm Post subject: (No subject) |
|
|
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
|
Posted: Wed Apr 13, 2005 2:29 pm Post subject: (No subject) |
|
|
code: |
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
|
Posted: Wed Apr 13, 2005 5:30 pm Post subject: (No subject) |
|
|
martin you just saved me sooo much time
this is what i did first for my "menu"
code: | 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
|
Posted: Wed Apr 13, 2005 9:54 pm Post subject: (No subject) |
|
|
battleroyale wrote:
Thanks alot. Now to learn how to do the infamous GUI.
any links will be appreciated.
[/code]
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. |
|
|
|
|
|
|