c++ beeping driving me insane!!!

Started by
14 comments, last by Timkin 16 years, 9 months ago
This program worked fine the other day, now it won't do anything. I'm working on a simple workout program, that will beep when exercises or rounds change (boxing). It is supposed to beep based on input, and worked fine but now it won't. Here's the code, please help, it deals with c++ and the cout << '\a' << flush sequence.
#include <fstream>
#include <iostream>
#include <windows.h>
#include <ctime>

using namespace std;

int main()
{
	double timer = 0;
	double lastTime = 0;

	double totalTime = 0;
    
	int numberOfRounds = 0;
	int exercises = 0;
	double* secondsPerRound = new double[100];


	cout << "Enter the number of EXERCISES PER ROUND : ";
	cin >> exercises;
	
	cout << endl;	

	cout << "Enter the number of rounds: ";
	cin >> numberOfRounds;

	cout << endl << "Exercises: " << exercises << endl << "Round: " << numberOfRounds;
	cout << endl;



		for (int i = 0; i < numberOfRounds; i++)
		{
			cout << "Round " << i + 1 << "  time (seconds): ";
			cin >> secondsPerRound;
		}

		timer = clock();
	
	
	for (int i = 0; i < numberOfRounds; i++)
	{		
		for (int j = 0; j < exercises; j++)
		{
			cout << "Waiting " << secondsPerRound << " seconds: " << endl;
			cout << '\a' << flush;

			lastTime = timer;
			timer = clock();
			totalTime += secondsPerRound;

			while(((timer - lastTime) / 1000) <= secondsPerRound)
			{
				timer = clock();
			}	
		}
	}

	cout << '\a' << flush;
    
	double minutes = 0;
	double seconds = 0;

	cout << "You have been going for: " << totalTime << " seconds,  or " << (int)(totalTime) / 60 << " minutes and " << (int)(totalTime) % 60 << " seconds";
	cout << endl << "Press any key" << endl;
	
	char key;

	cin >> key;


	return 0;
}
Advertisement
It's driving me crazy because I haven't changed any code and it worked yesterday but doesn't work today.

What's the deal?
It works on my computer so the problem probably isn't the code. Not sure what else it could be though.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Are you running a Console App by any chance? If so, have you observed any different font today than from yesterday, or from your other console windows?

This happened to me when I accidently changed the font somehow, and it made beeps as soon as some character was printf'd. Never found a solution though.
Yes, it's a console program. That's weired that it works on others computers. I don't know what to do.

No fonts are different. Is there any other way to make this thing beep? Using windows API seems disgusting... do I dare try it? And can I have console input like this program?
Try Beep():
#include <windows.h>...Beep (2, 2); 

The first parameter is the frequency, the second is duration
of the beep.

You dont need to change anything (cout/cin will still work).
Beep() doesn't work either. This blows. Maybe I should try to update my sound drivers on my computer?
Beep (750, 300);

This works for me.

If that doesnt work, try:
MessageBeep (-1);

Beep(750, 300) worked!!!

I love you. Thank god... I'm ready to blow up the house.

Awesome, you kick so much ass :)
Ah!!!!

Ok. Beep worked for a while, and now it's not. If I enter 2 for both exercises and rounds (should beep 5 times), it will only beep twice.

This topic is closed to new replies.

Advertisement