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

Username:   Password: 
 RegisterRegister   
 help with if statement.
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
netninja




PostPosted: Wed Feb 11, 2004 2:40 pm   Post subject: help with if statement.

Help with this please. At the get song part, it says its a bad get statement or something, and I dont understand why. Also, it says sonne (at the top) isnt declared, which i also dont understand. Obviously the program isnt finished, its just the beggining and i dont understand some things that I would like to learn in order to finish it. Of course it will only take half a minute, but im just practicing basics so that i can reach my final destination of making a duckhunt game hehe. Anyway, Im very noob to turing, so i appreciate all help with my errors.



setscreen ("graphics")

var song: array 1..6 of string:=init (sonne, zwitter, bodies, buckdich, ichwill, duhast)

put "sonne"
put "zwitter"
put "bodies"
put "buckdich"
put "ichwill"
put "duhast"
put ""
put "Enter the song you wish to play:"

get song

if song = sonne then
Music.PlayFileLoop ("music/sonne.mp3")
Draw.Text ("Sonne", 0, 0, defFontID, black)
end if

I also tried by making each song an integer instead of string, but that also didnt work. Laughing
Sponsor
Sponsor
Sponsor
sponsor
Zorg




PostPosted: Wed Feb 11, 2004 3:27 pm   Post subject: (No subject)

You have to declare another variable to store the user's input.
You have also stored the text into the array incorrectly.

Here is how it is done correctly:
var song : array 1 .. 6 of string := init ("sonne", "zwitter", "bodies", "buckdich", "ichwill", "duhast")


You also need to compare the user's input


var userinput:string
...
...
...
get userinput

if userinput = "sonne" then
Music.PlayFileLoop ("music/sonne.mp3")
Draw.Text ("Sonne", 0, 0, defFontID, black)
elsif userinput ="zwitter" then
..
...
...
..
end if
santabruzer




PostPosted: Wed Feb 11, 2004 3:29 pm   Post subject: (No subject)

... dude.. why did you do that.. when you could've done this:
code:

setscreen ("graphics")

var song
var songs : array 1 .. 6 of string := init (sonne, zwitter, bodies, buckdich, ichwill, duhast)

for i : 1 .. 6
    put songs (i)
end for
put ""
put "Enter the song you wish to play:"

get song

for i : 1 .. 6
    if song = songs (i) then
        Music.PlayFileLoop ("music/" + songs (i) + ".mp3")
        Draw.Text (songs (i), 0, 0, defFontID, black)
    end if
end for

netninja




PostPosted: Wed Feb 11, 2004 3:44 pm   Post subject: (No subject)

Laughing you ask why i did that??!!?? Because thats my knowledge of turing lol

But thanks alot, ill remember what you said! Thanks,

One more thing:

at the var songs: error says "syntax error at var, expected ':' "

and at the bottom at if song = songs (i) then: error says " operands of comparison operators must be scalars, sets, or strings.

Why is that?
recneps




PostPosted: Wed Feb 11, 2004 3:53 pm   Post subject: (No subject)

umm... lol maybe because song has no type assigned to it Smile

code:
var song
thats all it says, its gotta be var song:string or int depending on how its used.
netninja




PostPosted: Wed Feb 11, 2004 5:23 pm   Post subject: (No subject)

wow, that was shameful of me, so sorry,

lol, i cant believe i missed that, i guess my brain just skipped that step because its so basic lol, thanks for pointing it out though.

But why does it say that sonne is not declared?
Cervantes




PostPosted: Wed Feb 11, 2004 5:36 pm   Post subject: (No subject)

sonne is just the text contained within the variable songs (1) . to call it you have to call it like so songs (1) .
netninja




PostPosted: Wed Feb 11, 2004 6:01 pm   Post subject: (No subject)

no, the way santabruzer did it was by making (i) a song, i just cant seem to find the error in the code. I wanted to use that one because it seems more efficient, instead of having to declare 'if' so many times.

setscreen ("graphics")

var song :string
var songs : array 1 .. 6 of string := init (sonne, zwitter, bodies, buckdich, ichwill, duhast)

for i : 1 .. 6
if song = songs (i) then
put songs (i)
end for

put ""
put "Enter the song you wish to play:"

get song

for i : 1 .. 6
if song = songs (i) then
Music.PlayFileLoop ("music/" + songs (i) + ".mp3")
Draw.Text (songs (i), 0, 0, defFontID, black)
end if
end for

I just realized that there is two for statements, and two if statements, one of which has no end if. SO i ended the if, but the at the top it still gives the error i said before.
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Wed Feb 11, 2004 6:09 pm   Post subject: (No subject)

uh.. first of all the array is string, you have to put quotations in around the words, I don't see them...
code:

var songs : array 1 .. 6 of string := init (sonne, zwitter, bodies, buckdich, ichwill, duhast)

code:

for i : 1 .. 6
if song = songs (i) then
put songs (i)
end for %<---- forgot end if

the below prob is weird, i've always used more than 1 for loop with the same name and it worked, but if you change the below i to something else, that error won't occur...
code:

for i : 1 .. 6 %<--- thats weird, I've never had a prob with ths.
if song = songs (i) then
Music.PlayFileLoop ("music/" + songs (i) + ".mp3")
Draw.Text (songs (i), 0, 0, defFontID, black)
end if
end for


oh yea, the variable song has no value, so you can't use this:

code:

if song = songs (i) then
 

without first assigning song a value.
netninja




PostPosted: Wed Feb 11, 2004 6:19 pm   Post subject: (No subject)

Is song's value not song = songs + i ???
When i take away the 'then' , it gives me another error.

Also, now that i have the quotes, it says too few initial values, but thats not tru
Paul




PostPosted: Wed Feb 11, 2004 6:22 pm   Post subject: (No subject)

well there are problems here, what do you want to do?
if you need to compare 2 values, both variables MUST have values before you compare them.

like if you compare song and songs(i) to see if they're equal, song must first have a value to be compared.

If your trying to make song=songs(i) then the if statement is no good.
You have to have song:=songs(i)
netninja




PostPosted: Wed Feb 11, 2004 6:29 pm   Post subject: (No subject)

I want to be able to play the song which the user typed in, and thats it lol.

Mr Santabruzer gave me that code, and so far its been a drag Crying or Very sad
Paul




PostPosted: Wed Feb 11, 2004 6:33 pm   Post subject: (No subject)

he's code is fine, I just want to know why you have this:
for i : 1 .. 6
if song = songs (i) then
put songs (i)
end for
before you assigned a value to song.
I didn't see it in his code.
santabruzer




PostPosted: Wed Feb 11, 2004 6:33 pm   Post subject: (No subject)

ignore the Mr. Santabruzer code.. and do it the regular way.. once you are done that.. Mr. Santabruzer can implement his code upon your program.. if need be.. for effienciency.. Razz
netninja




PostPosted: Wed Feb 11, 2004 6:35 pm   Post subject: (No subject)

Ok, i did it, but somethings wrong with this one, and i know what it is lol
But i cannot fix it hehehe..

setscreen ("graphics")

var sonne, zwitter, bodies, buckdich, ichwill, duhast:string
var userinput:string

put "sonne"
put "zwitter"
put "bodies"
put "buckdich"
put "ichwill"
put "duhast"
put ""
put "Enter the song you wish to play:"

get userinput
sonne:=userinput
zwitter:=userinput
bodies:=userinput
buckdich:=userinput
duhast:=userinput
ichwill:=userinput



if userinput = sonne then
Music.PlayFileLoop ("music/sonne.mp3")
Draw.Text ("Sonne", 0, 0, defFontID, black)
end if

if userinput= zwitter then
Music.PlayFileLoop ("music/zwitter.mp3")
Draw.Text ("Sonne", 0, 0, defFontID, black)
end if

if userinput= bodies then
Music.PlayFileLoop ("music/bodies.mp3")
Draw.Text ("Sonne", 0, 0, defFontID, black)
end if

if userinput= buckdich then
Music.PlayFileLoop ("music/buckdich.mp3")
Draw.Text ("Sonne", 0, 0, defFontID, black)
end if

if userinput= ichwill then
Music.PlayFileLoop ("music/ichwill.mp3")
Draw.Text ("Sonne", 0, 0, defFontID, black)
end if

if userinput = duhast then
Music.PlayFileLoop ("music/duhast.mp3")
Draw.Text ("Du Hast",0,0, defFontID, black)
end if
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 2  [ 30 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: