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

Username:   Password: 
 RegisterRegister   
 music file
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hgrad98




PostPosted: Fri Oct 25, 2013 12:11 pm   Post subject: music file

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
a buzzer sound when the user inputs the wrong answer to an equation

What is the problem you are having?
i don't know how


Describe what you have tried to solve this problem
search the internet, help from a friend


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<Add your code here>



Please specify what version of Turing you are using
4.1
Sponsor
Sponsor
Sponsor
sponsor
Nathan4102




PostPosted: Fri Oct 25, 2013 12:31 pm   Post subject: RE:music file

Look into this http://compsci.ca/v3/viewtopic.php?t=190
hgrad98




PostPosted: Fri Oct 25, 2013 12:37 pm   Post subject: RE:music file

what is the special character a for? and it isnt working. is it for 4.1.1?
Nathan4102




PostPosted: Fri Oct 25, 2013 12:42 pm   Post subject: RE:music file

Look at the music part, the funny a thing is for playing single notes. Im assuming you want to play an audio file. If you're actually looking to do one note, the funny a thing just needs to be at the end, before the closing parenthesis it looks like. Just copy it into your code.
hgrad98




PostPosted: Fri Oct 25, 2013 12:44 pm   Post subject: RE:music file

ok here is my code:
if answer < num1 + num2 then
put "You are incorrect!!! Answer: ", num1 + num2
Music.PlayFile("buzzer.wav")
put ""
total := total + 0
end if
Music.SoundOff
Nathan4102




PostPosted: Fri Oct 25, 2013 1:16 pm   Post subject: RE:music file

Music.Playfile will occupy the main thread and lock the program until the music is finished playing. If that's fine with you, your code looks good, otherwise look into fork as shown in the link I posted earlier. I'd post the code but I'm on my phone right now.
hgrad98




PostPosted: Fri Oct 25, 2013 3:48 pm   Post subject: RE:music file

ok thanks. yea i was wondering why it didnt work. i knew the code was fine. but it still doesnt work. and now i really know it doesnt work because im at home and my computer is fine. the file length is 6 1/2 seconds at the most. do i have to have a delay (6500) in order for it to work? thanks
Nathan4102




PostPosted: Fri Oct 25, 2013 3:49 pm   Post subject: RE:music file

Can you show me the code you're currently using, plus any related procedures?
Sponsor
Sponsor
Sponsor
sponsor
hgrad98




PostPosted: Fri Oct 25, 2013 3:58 pm   Post subject: RE:music file

code:

%Title: Math Skills Improver/Quiz
%Created By: Hunter Grad
%Date Created: Wednesday October 23rd 2013, 12:38pm EST
%Time Of Last Edit: Wednesday October 23rd 2013, 12:47pm EST
%Course: ICS2O, Ms. Kirby
%************************************************************
%Declaring variables
var num1 : int %number 1 for computerized equation creation
var num2 : int %number 2 for computerized equation creation
var num3 : int %number 3 for computerized equation creation
var category : string %the category of math
var answer : int %user's answer input
var total : int %total number of correct answers in one game
var total2 : int %total number of correct answers in another game
var total3 : int %total number of correct answers in yet another game
var total4 : int %total number of correct answers in another different game.
total := 0 %setting the total to 0 so 1 gets added on every time the user's answer is correct
total2 := 0 %setting the total2 to 0 so 1 gets added on every time the user's anser is correct
total3 := 0 %setting the total2 to 0 so 1 gets added on every time the user's anser is correct
total4 := 0 %setting the total2 to 0 so 1 gets added on every time the user's anser is correct
var response : string %response fom user after computer asks if they want to restart.
var hugetotal : int %The overall total at the end of the game
var randomnumber : int %a number needed to make the final calculation at the end
var randomnumber2 : int %a number needed to make the final calculation at the end
var randomnumber3 : int %a number needed to make the final calculation at the end
var randomnumber4 : int %a number needed to make the final calculation at the end
randomnumber := 0 %setting the 1st random number to 0
randomnumber2 := 0 %setting the 2nd random number to 0
randomnumber3 := 0 %setting the 3rd random number to 0
randomnumber4 := 0 %setting the 4th random number to 0
var score : string %used for asking the user if they want to see their total score at the end of the quiz.
%************************************************************
loop

put "This is a math quiz that can help to improve your math skills." %telling the user what the program is
delay (5000)
cls %clear screen
delay (500)
put "There are five (5) different categories that you can take the quiz in."
put ""
put "Addition Subtraction Multiplication Division and All" %categories
put ""
put "Please type in the category you would like to take the quiz in." %they type in the name of the category of what they want to take the quiz on to take it
get category
cls

if category = "Addition" then %checking if the user chose the category "Addition"
color (55)
put "You chose Addition!"
color (black)
for i : 1 .. 20

randint (num1, 1, 30) %coming up with a random number between 1 and 30
num1 := Rand.Int (1, 30)
randint (num2, 1, 30) %coming up with a random number between 1 and 30
num2 := Rand.Int (1, 30)
put "What is ", num1, " + ", num2, "?" %asking the user a question
put "=" ..
get answer
color (49) %changing the "correct" color to green

if answer = num1 + num2 then
put "You are correct!!!"
put ""
total := total + 1
end if

color (12) %changing the "incorrect" color to red

if answer > num1 + num2 then
put "You are incorrect!!! Answer: ", num1 + num2
Music.PlayFile("buzzer.wav")
put ""
total := total + 0
end if

if answer < num1 + num2 then
put "You are incorrect!!! Answer: ", num1 + num2
Music.PlayFile("buzzer.wav")
put ""
total := total + 0
end if
Music.SoundOff
randomnumber := randomnumber + 1
color (black)

end for
put ""
put "Your total number of correct answers in this game is: ", total, "/20."
put "Percentage: ", total * 5, "%" %total number of correct answers as a percentage
put ""
put "Do you want to take the test again? -> " .. %does the user want to take the quiz again?
get response
put ""
exit when response = "no" %exit program if the user doesn't want to continue
end if

if category = "Subtraction" then %checking if the user chose the category "Subtraction"

color (11)

put "You chose Subtraction!"
color (black)
for i : 1 .. 20

randint (num1, 15, 30) %coming up with a random number between and including 15 and 30
num1 := Rand.Int (15, 30) %i chose to make sure that the answer will never be negative by making num1 bigger than num2 always.
randint (num2, 1, 14) %coming up with a random number between and including 1 and 14
num2 := Rand.Int (1, 14)
put "What is ", num1, " - ", num2, "?" %asking the user a question
put "=" ..
get answer

color (49) %changing the "correct" color to green

if answer = num1 - num2 then
put "You are correct!!!"
put ""
total2 := total2 + 1
end if

color (12) %changing the "incorrect" color to red

if answer > num1 - num2 then
put "You are incorrect!!! Answer: ", num1 - num2
put ""
total2 := total2 + 0
end if

if answer < num1 - num2 then
put "You are incorrect!!! Answer: ", num1 - num2
put ""
total2 := total2 + 0
end if

randomnumber2 := randomnumber2 + 1
color (black)

end for
put ""
put "Your total number of correct answers in this game is: ", total2, "/20."
put "Percentage: ", total2 * 5, "%" %total number of correct answers as a percentage
put ""
put "Do you want to take the test again? -> " .. %does the user want to take the quiz again?
get response
put ""
exit when response = "no" %exit program if the user doesn't want to continue
end if

if category = "Multiplication" then %checking if the user chose the category "Multiplication"
color (purple)
put "You chose Multiplication!"
color (black)
for i : 1 .. 20

randint (num1, 1, 12) %coming up with a random number between and including 1 and 12
num1 := Rand.Int (1, 12)
randint (num2, 1, 12) %coming up with a random number between and including 1 and 12
num2 := Rand.Int (1, 12)
put "What is ", num1, " x ", num2, "?" %asking the user a question
put "=" ..
get answer
color (49) %chaning the "correct" color to green

if answer = num1 * num2 then
put "You are correct!!!"
put ""
total3 := total3 + 1
end if

color (12) %chaning the "incorrect" color to red

if answer > num1 * num2 then
put "You are incorrect!!! Answer: ", num1 * num2
put ""
total3 := total3 + 0
end if

if answer < num1 * num2 then
put "You are incorrect!!! Answer: ", num1 * num2
put ""
total3 := total3 + 0
end if

randomnumber3 := randomnumber3 + 1
color (black)

end for
put ""
put "your total number of correct answers in this game is: ", total3, "/20."
put "Percentage: ", total3 * 5, "%" %number of correct answers as a percentage
put ""
put "Do you want to take the test again? -> " .. %does the user want to take the quiz again?
get response
put ""
exit when response = "no" %exit program if the user doesn't want to continue

end if

if category = "Division" then
color (35)
put "You chose Division!"
color (black)
for i : 1 .. 20

randint (num1, 1, 12)
num1 := Rand.Int (1, 12)
randint (num2, 1, 12)
num2 := Rand.Int (1, 12)
num3 := num1 * num2
put "What is ", num3, " ? ", num2, "?"
put "=" ..
get answer

color (49) %changing the "correct" color to green

if answer = num3 / num2 then
put "You are correct!!!"
put ""
total4 := total4 + 1
end if

color (12) %changing the "incorrect" color to red

if answer > num3 / num2 then
put "You are incorrect!!! Answer: ", num3 / num2
put ""
total4 := total4 + 0
end if

if answer < num3 / num2 then
put "You are incorrect!!!"
put ""
total4 := total4 + 0
end if

randomnumber4 := randomnumber4 + 1
color (black)

end for
put ""
put "Your total number of correct answers in this game is: ", total4, "/20."
put "Percentage: ", total4 * 5, "%"
put ""
put "Do you want to take the quiz again? -> " ..
get response
put ""
exit when response = "no"

end if

end loop

put "Would you like to know your score? (yes/no) " ..
get score
if score = "yes" then
put "Your overall total for every game you played together is: ", total + total2 + total3 + total4, "/", (randomnumber + randomnumber2 + randomnumber3 + randomnumber4)
put "Overall percentage: %", ((total + total2 + total3 + total4) / (randomnumber + randomnumber2 + randomnumber3 + randomnumber4)) * 100
end if

if score = "no" then
put "Ok. Hope you try again some time soon! Bye!"
end if
hgrad98




PostPosted: Fri Oct 25, 2013 3:58 pm   Post subject: RE:music file

it is formatted properly on turing. the text box ruined the tabbing.
hgrad98




PostPosted: Fri Oct 25, 2013 3:59 pm   Post subject: RE:music file

it is in the 5th "paragraph"
Nathan4102




PostPosted: Fri Oct 25, 2013 4:16 pm   Post subject: RE:music file

To retain the format, put the code in [syntax="turing"] tags. I'd suggest making a procedure which plays the music, and then whenever you want to play the music, call "Fork procedureName".
hgrad98




PostPosted: Fri Oct 25, 2013 4:47 pm   Post subject: RE:music file

ok thanks but in class we didnt do procedures i dont think
Raknarg




PostPosted: Fri Oct 25, 2013 8:48 pm   Post subject: RE:music file

You can always learn how! Getting ahead is good for marks and makes a good impression on teachers. Not to mention that if you're interested in something, you might as well learn more about it.

The Turing Walkthrough
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 1  [ 14 Posts ]
Jump to:   


Style:  
Search: