How to put sound in c++?

Asked

Viewed 1,163 times

-1

I’m still new with programming and wanted to put the sound of Super Mario inside a college project, as I do so it can work?

Code:

int certo=0,errado=0,certoVF=0,certoA=0; 
char resposta,r1,r2,r3,r4,r5,r6,r7; 
int nivel,v,x; 

printf ("\t| 0 - SAIR DO GAME |\n"); 
printf ("\t| 1 - JOGAR TODOS OS NÍVEIS |\n"); 
printf ("\t| 2 - JOGAR NIVEL FÁCIL - SOMENTE O NIVEL FÁCIL |\n"); 
printf ("\t| 3 - JOGAR NIVEL MÉDIO - SOMENTE O NIVEL MÉDIO |\n"); 
printf ("\t| 4 - JOGAR NIVEL DIFÍCIL - SOMENTE O NIVEL DIFÍCIL |\n");
printf ("\t Oque deseja fazer? "); 
scanf ("%d",&nivel);
  • 1

    What is your OS? Already have some code or searched something?

  • windows, I found the sound code, but at the time of putting in the game code did not work

  • 1

    If possible edit the question by adding the code snippet where you insert the function calling the sound, followed by the error (if you have given any). Then we can give a direction :)

  • I got it right at the beginning, tried to use the for and right after the code of the game menu, then beep them to make the sound. only that he plays the music and does not go forward with the questions

1 answer

2


In the Soen there is a similar question, the answer being marked as correct, the use of the function Beep, as follows:

#include <iostream> 
#include <windows.h> // header do WinApi

using namespace std;

int main() 
{ 
    Beep(523,500); // 523 hertz (C5) por 500 milissegundos (0,5 segundos)
    cin.get(); // espera tocar o som
    return 0; 
}

Documentation of function Beep if you want to see.

  • ah yes, thank you very much

  • int certo=0,wrong=0,certoVF=0,certoA=0; char reply,R1,R2,R3,R4,R5,R6,R7; int nivel,v,x; printf (" t| 0 - EXIT GAME | n"); printf (" t| 1 - PLAY ALL LEVELS | n"); printf (" t| 2 - PLAY EASY LEVEL - ONLY THE EASY LEVEL | n"); printf (" t| 3 - PLAY MEDIUM LEVEL - ONLY MEDIUM LEVEL | n"); printf (" t| 4 - PLAY HARD LEVEL - ONLY HARD LEVEL | n") printf (" t What do you want to do? " ); scanf ("%d",&nivel);

  • then when I chose a value other than 0 the music would be playing. Is there any way to do this?

  • @Murilo, I edited your question and added the code, in the comment is difficult to read and understand.

  • ah yes, thank you very much :)

  • And to answer your question, you make a if and checks if it is different from 0, if yes you run the code I showed in the answer, do the test and see if it works.

  • Aham, I’ll try here, thanks for the help

  • @Murilo some progress?

  • I and some colleagues from college put to play and then start, as we are new in programming, we do not have the knowledge so wide to make two tasks to be performed at the same time, but it was of great help the explanation.

  • Okay, if you can close the question, not to be open, just click the arrow next to the vote, the question.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.