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 Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
netninja




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

I also have another way, that is better i think, one sec, im going to have to write it.
Sponsor
Sponsor
Sponsor
sponsor
santabruzer




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

literal string Rolling Eyes
code:
setscreen ("graphics")

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

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
Paul




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

I haven't had anything go wrong, except the text overlaps? is that what you mean? oh yea, and is duhast Ramstein?
I also don't get why this is here:
code:

if userinput = sonne then

when you have this before it
code:

sonne:=userinput

theres no point to that if statement, because whatever the user inputs, the user input will be always equal to all of them, so the text overlaps?
santabruzer




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

yea.. i think it is.. well at least the last time i checked.. Rolling Eyes
netninja




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

All those are Rammstein except for bodies (Let the bodies hit the floor) by i forgot lol

I just didnt want to write out the whole thing. It seems that rock music is really good when your playing a game, it livens you up. Or at least makes you feel like playing. I think it works best on killing games. I donno what im talking about, but thanks for the help.

Thats exactly what i was about to do, but i didnt finish.

But i wanted to learn how to do it using (i)
Could you help please? Sorry, im eating, very slow. Sorry to be such a botherer, if you could point me in the right direction would be the best to teach me how i could do it using the (i). Im having troubles with it.
santabruzer




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

and array i simple one "var" with alot of different values.. think of it.. as many Variables compressed into one.. so if you declare and array with

code:
var test : array 1 .. 5 of string


there are going to be 5 values to test.. hence test (1), test (2) ... test (5).

now.. if for example i want to give them all a zero value.. i could either initialize them.. or i can do the following:

code:
for i : 1 .. 5
test (i) := 0
end for


there basically all i'm doing is for every value of the array i'm making the value equal to zero.. by accessing the array with the brackets.. after the variable..

In your problem.. it's easier to use an array, because you are doing the same thing over and over again... so you could do something like this:

code:
var songs : array 1 .. 5 := init ("asdasdasd", "aaasadsd","abdasdasd","avdasasdd","aasdasasdd")
for i : 1 .. 5
     put songs (i)
end for
% The above will output the songs name

var choice : string
% Have a variable for the user's song choice

for i : 1 .. 5
if choice = songs (i) then
     % Play the song here.. etc.. Output the name by putting "songs (i)", no quotes..

end for
% This will compare the user's input to the array.
netninja




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

Thanks
netninja




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

Why does it say "too few initial values?" thats exactly what it said before...

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

for i : 1 .. 5

put songs (i)
end for

var choice : string
for i : 1 .. 5

if choice = songs (i) then
Music.PlayFileLoop ("music/"+songs (i)+".mp3")
Draw.Text (songs (i), 0, 0, defFontID, black)

end if end for

i understood almost everything you said before, but when you explained it, i thought i understood everything 100%. and still gets the same error, im Mad
Sponsor
Sponsor
Sponsor
sponsor
santabruzer




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

because.. you must put quotes as follows:
code:
var songs : array 1 .. 6 of string := init ("sonne", "duhast", "ichwill", "bodies", "buckdich", "zwitter")
netninja




PostPosted: Wed Feb 11, 2004 7:14 pm   Post subject: (No subject)

Ahh, thats important heh, thanks alot, want some bits? Although i dont know how to give them to you heh

That helped a LOT! Whew. NOoooOOOOOooo, more problems!

It says choice has not been declared, where do i put get choice? NVM BOOYAH, i got it, finally, array has been mastered! I just didnt check hard enough. Now onto records... Array is still not fully mastered Wink
Paul




PostPosted: Wed Feb 11, 2004 7:17 pm   Post subject: (No subject)

You donate by clicking donate beneath his pic, (see? I help). I'll donate bits to him for you, seeing as you don't have much.
netninja




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

Thanks alot, for teaching me, and for donating.
santabruzer




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

I have a feeling i have to do this anyways.. but i'll do my txt program.. as an example.. ok..

what is a record?

A record is a very simple way to record information. Hence the name. Like a company record, what a record does, is give many variables.. such as name, company, s/n.. etc.. all assigned under one varaible.. and thus makes life so much easier..
Records could also be used for x and y locations..

code:
type coord : record
      x, y : int
end record


that's is how i declared the Co-Ord record.. now i must declare the "universal" variable, for these records.. and so i get:
code:
var text : coord

This would mean that text has to "sub" variables. as declared in the record before.. so it would be:

code:
text.x
text.y


now.. obviously this can be used with an array.. for some things.. like if you want to create some records.. for iono.. a company you would do:

code:
type companyfile : record
name, address : string
sn : int
end record


.. hence you would have one record.. then declare a variable .. and you'd probably want to declare an array.. becuase there are probably gonna be more than one person right?

code:
var employee : array 1 .. 5


then you could do the following:

code:

for i : 1 .. 5
    put "Please enter your name:"
    get employee (i).name : *
    put "Please enter your address:"
    get employee (i).address : *
    put "Please enter your S/N:"
    get employee (i).sn
end for


there you go... if you actually want to see a cool program.. reply with : "i want to see a cool program".. of course that is if you didn't see my mouse name display program Razz
netninja




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

i want to see a cool program Razz
santabruzer




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

ha ha.. found it Very Happy
http://www.compsci.ca/v2/viewtopic.php?t=3003
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 2 of 2  [ 30 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: