Introduction: C++: for Loop With Beeps (Windows)

About: Occupation: tech support

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

Supplies

  1. Code::Blocks IDE for C++
  2. Desktop or laptop with Windows

Step 1:

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