Page 1 of 1

Adding a Beep & delay to a C/C++ Console

Posted: Thu Jun 23, 2011 3:05 pm
by RAT16F88
Adding a Beep and a Delay to Our consoles come handy and useful in many instances so I just Google and found it so I decided to share it with my mates :) :) :)


example for beep

Code: Select all

#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;
int freq , interval ; 
int main( )
{
     printf("what is ur desired frequency ? :- "); //frequency in Hz
     scanf("%d",&freq);
     printf("\n what is ur desired interval ? :- "); // interval in milliseconds
     scanf("%d",&interval);
     Beep(freq,interval);
     system("PAUSE");
     return EXIT_SUCCESS;
}

}

example for Delay

Code: Select all

#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;
int delay ; 
int main( )
{
     printf("what is ur desired delay ? :- "); //delay in milliseconds
     scanf("%d",&delay);
     system("cls"); // clear screen
   do{
       printf("($)_($)");
       Sleep(delay);
       system("cls"); // clear screen
       Sleep(delay);
       }while(1);
       
}

Re: Adding a Beep & delay to a C/C++ Console

Posted: Thu Jun 23, 2011 4:10 pm
by Saman
Very nice. Thanks for sharing.

FYI: Since you have used windows.h, this will only work on Windows. Both Beep and Sleep are Windows API function.

Re: Adding a Beep & delay to a C/C++ Console

Posted: Thu Jun 23, 2011 11:12 pm
by Neo
Very nice. REP+

Re: Adding a Beep & delay to a C/C++ Console

Posted: Fri Jun 24, 2011 12:03 pm
by Nipuna
Cool.

After Long a time Man :)