C++: for Loop With Beeps (Windows)

by matt392 in Circuits > Software

8 Views, 0 Favorites, 0 Comments

C++: for Loop With Beeps (Windows)

beeps.jpg

For loop using Beep() function in Windows:

#include <iostream> 
#include <windows.h> // Need this library for Beep() function

using namespace std;

int main()

{ // start main function

int NumberOfBeeps;
int alpha;

cout << "Enter the number of beeps you would like to hear: ";
cin >> NumberOfBeeps;

for (alpha=1; alpha<=NumberOfBeeps; alpha++)
{
cout << "Beep at the frequency of 1,000 hertz for 750 milliseconds per beep.\n";
Beep(1000, 750); // Beep frequency at 1,000 hertz for 750 milliseconds
// Note the Beep() function only works on Windows!
} // end for loop

return 0;

} // end main function

Downloads

Supplies

codeblockslogo.png
desktopcomputer.jpg
c++image.jpg
  1. Code::Blocks IDE for C++
  2. Desktop or laptop with Windows

for-loop-steps.png
beep1.png
beep3.png

For loop using Beep() function in Windows:

#include <iostream> 
#include <windows.h> // Need this library for Beep() function

using namespace std;

int main()

{ // start main function

int NumberOfBeeps;
int alpha;

cout << "Enter the number of beeps you would like to hear: ";
cin >> NumberOfBeeps;

for (alpha=1; alpha<=NumberOfBeeps; alpha++)
{
cout << "Beep at the frequency of 1,000 hertz for 750 milliseconds per beep.\n";
Beep(1000, 750); // Beep frequency at 1,000 hertz for 750 milliseconds
// Note the Beep() function only works on Windows!
} // end for loop

return 0;

} // end main function

Downloads