beepclock code attempt 2

  • From: "Alex Hall" <mehgcap@xxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 6 Jun 2008 23:45:50 -0400

Here is a second attempt, from a pc this time, to send the code for 
beepclock.cpp. See my previous message for an explanation of the loop at the 
end of the file.

Code:
#include <conio.h>
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main () {
int end=0;
int min=0;//stores current system minutes
int min2=0;//stores minutes as well, used to make infinite loop so beeps do not 
happen
//multiple times for the same minute
int hour=0;//stores current hour
bool beeps=true;//'true' is beeps enabled, 'false' is silence
string cmd;
cout<<"This program beeps once on the quarter hour, twice on the half, and 
three times at quarter of the hour, all at 488 mhz. Each hour it beeps as many 
times as the hour is at 244mhz. To silence beeps, type \"s\", and to enable 
beeps again type \"b\". To exit, press either \"e\" or \"q\".\n";
while(end==0){//loop not supposed to ever end so monitoring of sys clock and
//beep alerts continue until prog killed
time_t now=time(NULL);//get current time in secs from 01-01-70
tm* t =localtime(&now);//convert to tm struct for getting minutes later
min=t->tm_min;//get minutes from said tm struct
min2=min;//used for loop at the end of this main loop
hour=t->tm_hour;//now get hours
if(hour>12) hour-=12;
if(hour==0)hour=12;
if(min==0&&beeps){
for(int i=0;i<hour;i++){
Beep(244, 500);
Sleep(500);
}
}
else{
if(min==15&&beeps){//15 past the hour, beep once
Beep(488, 500);
}
else if(min==30&&beeps){//half past, beep twice
Beep(488, 500);
Sleep(500);
Beep(488, 500);
}
else if(min==45&&beeps){//quarter of, beep 3 times
Beep(488, 500);
Sleep(500);
Beep(488, 500);
Sleep(500);
Beep(488, 500);
}
}
while(min==min2){
time_t now=time(NULL);//get current time in secs from 01-01-70
tm* t =localtime(&now);//convert to tm struct for getting minutes later
min2=t->tm_min;//get minutes again to see if this loop should end
//cmd=getch();//this loop is good for input
//because it is almost always running, getch gets char from kbd w/o <enter>
if(cmd=="s"){
beeps=false;
system("cls");
cout<<"Beeps disabled, type \"b\" to enable.\n";
}
else if(cmd=="b"){
beeps=true;
system("cls");
cout<<"Beeps enabled, type \"s\" to disable.\n";
}
else if(cmd=="e"||cmd=="q"){
exit(0);
}
}
//cout<<"test";//alerts exiting of subloop, for testing
}
cin.get();
return false;
}

Have a great day,
Alex

Other related posts: