hey everyone am trying to generate a beeping sound on my pc using the 'sound' function , the problem is i am getting errors (5 to be exact ) when i compile this program , please someone point out the error on this code , thanx :) below is the code-

#include <dos.h>
#include <conio.h>

int main()


{
     unsigned frequency;
     do
        {
              for (frequency = 500; frequency  <= 1000; frequency += 50)
                {
                             sound(frequency);
                             delay(50);
                             } 
                for (frequency = 1000; frequency >= 500; frequency -= 50)
                { 
                    sound(frequency);
                    delay(50);
                       }
                    }
                    while (! kbhit());
                    nosound();


 system("PAUSE");
 return 0; 
}

Recommended Answers

All 3 Replies

Looks like very old Borland code. What compiler are you using?

am actually using dev c++ , and it took alot for me to come up with the code :( are you gonna help or what ?

commented: Nice attitude: I don't know what I'm doing - do it for me. Now! +0

I admittedly have better things to do than to fugg around with old Borland code. This however works with the Dev-C++ compiler. I commented out the Turbo gibberish!

//#include <dos.h>
//#include <conio.h>

#include <cstdlib>     // system()
#include <iostream>    // access to stdio.h
#include <windows.h>   // Beep()

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define ESC     27     // escape key

int main()
{
  unsigned frequency;

  printf("Keep hitting the escape key to stop ...");
  do
  {
    for (frequency = 500; frequency <= 1000; frequency += 50)
    {
      Beep(frequency,50);
      //sound(frequency);
      //delay(50);
    } 
    for (frequency = 1000; frequency >= 500; frequency -= 50)
    {
      Beep(frequency,50); 
      //sound(frequency);
      //delay(50);
    }
  } while(!KEY_DOWN(ESC));
  //while (! kbhit());
  //nosound();

  system("PAUSE");
  return 0; 
}

Next time ask a little nicer!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.