My program acts unexpectedly

Hi there!. I just wrote some code; it asks the user to input:

Frequency (in int number value)
Mark duration (in secs)
Space duration (in secs)
and the number of repeats required (whole number)

It repeats the correct number of times as expected, BUT the SPACE duration (the specified timed break between beeps) is messed up... HELP!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
int HZ=0;
int DUR=0;
int BRK=0;
int RPT=0;
cout << "Enter freq. in Hz (whole numbers please!)\n\n";
cin >> HZ;
cout << "\nEnter duration in Seconds\n\n";
cin >> DUR;
cout << "\nEnter break in Seconds\n\n";
cin >> BRK;
cout << "\nEnter number of repeats:";
cin >> RPT;
{
for (int repeat=0; repeat < RPT; repeat++)
Beep(HZ,DUR*1000);
Sleep(BRK*1000);
}
return 0;
}


I don't know what Beep and Sleep are, but look at your braces
shouldn't it be:
1
2
3
4
5
6
for (int repeat=0; repeat < RPT; repeat++)
{
   Beep(HZ,DUR*1000);
   Sleep(BRK*1000);
}

The way you have it, it will beep RPT number of times, then sleep after all the beeps are done.
Last edited on
Ahhh stupido el Me! Perfect!!. Many thanks from the UK! :-)): Fixed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
int HZ=0;
int DUR=0;
int BRK=0;
int RPT=0;
cout << "Enter freq. in Hz (whole numbers please!)\n\n";
cin >> HZ;
cout << "\nEnter duration in milliSeconds\n\n";
cin >> DUR;
cout << "\nEnter break in milliSeconds\n\n";
cin >> BRK;
cout << "\nEnter number of repeats:";
cin >> RPT;
for (int repeat=0; repeat < RPT; repeat++)
{
Beep(HZ,DUR);
Sleep(BRK);
}
return 0;
}


Last edited on
Isn't it like 3 in the morning there?
No it's 01:06am... why? :S
just curious..I always make mistakes when writing code in the middle of the night
No I'm just dumb haha!. :P
Topic archived. No new replies allowed.