Jump to content
  • Advertisement
Sign in to follow this  
heyman

c++ beeping driving me insane!!!

This topic is 3993 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Beep() doesn't work either. This blows. Maybe I should try to update my sound drivers on my computer?

Share this post


Link to post
Share on other sites
Beep(750, 300) worked!!!

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

Awesome, you kick so much ass :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!