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

C, C++, Visual C++, C++.Net Topics
Post Reply
RAT16F88
Lieutenant
Lieutenant
Posts: 72
Joined: Sat Nov 20, 2010 12:36 pm
Location: Inside a PIC

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

Post by RAT16F88 » Thu Jun 23, 2011 3:05 pm

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);
       
}
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

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

Post by Saman » Thu Jun 23, 2011 4:10 pm

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.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

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

Post by Neo » Thu Jun 23, 2011 11:12 pm

Very nice. REP+
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

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

Post by Nipuna » Fri Jun 24, 2011 12:03 pm

Cool.

After Long a time Man :)
Post Reply

Return to “C/C++ Programming”