audible beep?

the program i want to write is as follows:

a program that uses a do-while statement. It reads in an integer
n from the keyboard. If n is not in the range 1 to 10 it makes an audible
"beep" and asks for another integer. If n is in the correct range, it writes
out "You have input n" and then exits.

I am having trouble executing the audible "beep" part. Im not 100% sure if what I've done so far is correct, none the less this is what I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#include <iostream>
using namesapce std

int main() {

int n

do {

cout << "Please input an integer:";
cin >> n;

if(n>=1 && n<=10) {

cout << "You have input n:";
exit (1);
                  }

else {

cout << "Not in range, please input another number:";
cin >> n;

     }

while(n>=1 && n<=10) 

return o;

}




Last edited on
If you can use it, there is the windows API which provides the Beep function

eg:
1
2
3
4
5
6
7
8
#include <windows.h>

int main()
{
    unsigned long Hz = 440, Millisecs = 500;
    Beep(Hz,Millisecs);
    return 0;
}


http://msdn.microsoft.com/en-us/library/ms679277.aspx
closed account (z05DSL3A)
std::cout << '\7';
what does std::cout << '\7'; do?
Last edited on
'\7' is the same as '\a' and it's the 'alert' character which will produce a beep if in the output of the console
Topic archived. No new replies allowed.