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; 
}

Dani AI

Generated

Quick diagnosis and what caused the five errors
Your original snippet uses DOS/Turbo C era helpers (the old dos/conio-style headers and PC‑speaker helpers). Those headers and routines are non‑standard, tied to real‑mode DOS, and aren’t supplied by modern MinGW/Dev‑C++ toolchains — that is why the compiler reports missing symbols. If you really need the original DOS behaviour, run the program inside an emulator or use an old Turbo toolchain; otherwise you should port the calls to modern APIs. (geeksforgeeks.org)

Why ’s suggestion helps (and one small correction)
Moving away from <dos.h>/<conio.h> to native APIs is the right approach. On Windows, the OS exposes tone and timing services you can call from a native program, and modern thread sleep APIs replace the old delay() calls. ’s rewrite is correct in spirit; a minor fix is to include the proper header for C printf (for example <cstdio> or <stdio.h>) rather than relying on an iostream include. Also remember that “conio” behavior varies by toolchain — MinGW/Dev‑C++ may supply a different conio implementation or a compatibility library. (learn.microsoft.com)

Portability and realistic choices
Be aware that modern hardware/OS sometimes ignore or emulate the PC speaker, so results differ by machine. For anything beyond a simple tone, use a purpose-built audio API or library (PortAudio, SDL, etc.) — they let you play sine waves or actual audio files reliably across platforms. If the assignment requires the old Borland calls, use DOSBox or a legacy compiler instead of trying to force them into MinGW. (portaudio.com)

Quick troubleshooting checklist

  1. Remove the Turbo/DOS headers and calls.
  2. On Windows, call the OS audio/timing APIs (documented in the Win32 reference) and include correct headers.
  3. If you must keep conio-style keyboard polling, install a MinGW/Demo conio compatibility library or use platform APIs for nonblocking input.
  4. For cross‑platform audio, pick PortAudio or SDL and follow their tutorials.

Mentioning : start with step 1 (remove the old headers) and pick either “port to a modern API” or “run under DOSBox” depending on whether you need exact legacy behavior. (stackoverflow.com)

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.