Jump to content

C++ code

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
12 replies to this topic

#1
Pitufo

Pitufo

    Newbie

  • Members
  • Pip
  • 4 posts
I have this code but I dont know why it doesnt want to play the umemba, loser, or winner sound. It does compile but when i insert a one, or two, or something else, it just freezes...the only song that works is tetris...Can someone help me...

#include <windows.h>
#include<iostream>

using namespace std;

DWORD WINAPI dwThread(LPVOID);

int main()
{
HANDLE hThread;
while(hThread)
{
hThread=CreateThread(NULL,3,dwThread,0,3,NULL);
WaitForSingleObject(hThread,3);
}
char lname[34];
int number;
char name[35];
cout<<"Please enter your name."<<endl;
cin>>name;
cout<<"enter 1 or 2"<<endl;
cin>>number;

if(number==1)
{
PlaySound("umemba.wav",NULL,SND_ASYNC);
}
if (number==2)
{
PlaySound("loser.wav",NULL, SND_ASYNC);
}
else
{
PlaySound("winner.wav",NULL, SND_ASYNC);
}

cout<<"You loser"<<name<<endl;

cout<<"please enter your last name"<<endl;
cin>>lname;
return 0;
}

DWORD WINAPI dwThread(LPVOID)
{
PlaySound("tetris.wav",NULL,SND_FILENAME);
ExitThread(1);
}

Edited by WingedPanther, 24 April 2008 - 03:56 PM.
add code tags


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Are you able to play all the sounds with a regular sound player? All all the sound files located in the same folder?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Pitufo

Pitufo

    Newbie

  • Members
  • Pip
  • 4 posts
yes the songs work perfectly but the thing is that they wont work in the program...and they are in the same folder...what should i do...

#4
Pitufo

Pitufo

    Newbie

  • Members
  • Pip
  • 4 posts
#include <windows.h>
#include<iostream>

using namespace std;

DWORD WINAPI dwThread(LPVOID);
DWORD WINAPI dwUmemba(LPVOID);
DWORD WINAPI dwLoser(LPVOID);
DWORD WINAPI dwWinner(LPVOID);
int main()
{
  HANDLE hThread;
    while(hThread)
    {
        hThread=CreateThread(NULL,1,dwThread,0,1,NULL);
        WaitForSingleObject(hThread,1);
    }  
  char lname[34];  
  int number;  
  char name[35];
  cout<<"Please enter your name."<<endl;
  cin>>name;
  cout<<"enter 3 or 4"<<endl;
  cin>>number;
  
  if(number==3)
  {
               HANDLE hThread;
               while(hThread)
               {
                              hThread=CreateThread(NULL,1,dwUmemba,0,1,NULL);
                              WaitForSingleObject(hThread,1);
               }
                
  }
 else if (number==4)
 {
               HANDLE hThread;
               while(hThread)
               {
                              hThread=CreateThread(NULL,1,dwLoser,0,1,NULL);
                              WaitForSingleObject(hThread,1);
               }
                
 }
 else 
 {
               HANDLE hThread;
               while(hThread)
               {
                              hThread=CreateThread(NULL,1,dwWinner,0,1,NULL);
                              WaitForSingleObject(hThread,1);
               }
                
               PlaySound("winner.wav",NULL,SND_FILENAME | SND_ASYNC);
 }
 
    cout<<"You loser"<<name<<endl;
    
    cout<<"please enter your last name"<<endl;
    cin>>lname;
    return 0;
}

DWORD WINAPI dwThread(LPVOID)
{
    PlaySound("tetris.wav",NULL,SND_FILENAME);
    ExitThread(0);
}

DWORD WINAPI dwUmemba(LPVOID)
{
    PlaySound("umemba.wav",NULL,SND_FILENAME);
    ExitThread(0);
}
DWORD WINAPI dwLoser(LPVOID)
{
    PlaySound("loser.wav",NULL,SND_FILENAME);
    ExitThread(0);
}
DWORD WINAPI dwWinner(LPVOID)
{
    PlaySound("winner.wav",NULL,SND_FILENAME);
    ExitThread(0);
}

Edited by WingedPanther, 25 April 2008 - 08:57 AM.
fix code tags... again


#5
Pitufo

Pitufo

    Newbie

  • Members
  • Pip
  • 4 posts
Now i tried the code above but it doesnt work...

#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
It's actually against the forum rules to double-post in a thread. I won't (and can't) give you an infraction, but take it from me - the evil tyrant John has inflicted two on me!
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Just an observation: you are not issuing the same parameters when you call PlaySound(). That may be the issue.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#8
R-G

R-G

    Programmer

  • Members
  • PipPipPipPip
  • 142 posts
Xav, cool down, it is not. If you read the source software code algorithm carefully enough you'll see that it isn't the same message at all.
Like an angel without a sense of mercy.

#9
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
R-G, stop contradicting me. If you read the forum rules carefully enough, you'll see that it's against the rules to post two posts back to back. It doesn't matter what's in the posts - you're not allowed two of your own posts together, without a reply from someone else. :mad:
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#10
R-G

R-G

    Programmer

  • Members
  • PipPipPipPip
  • 142 posts
Oh yes, I'm so sorry, the whole HTTP computer server machine will pass by, because of this major mistake.
Like an angel without a sense of mercy.

#11
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
R-G, please. I'm only trying to teach Pitufo the rules of CodeCall. I received two infractions from John for double posting - I don't want the same thing to happen to him.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#12
R-G

R-G

    Programmer

  • Members
  • PipPipPipPip
  • 142 posts
Alright.
Like an angel without a sense of mercy.