PDA

View Full Version : C++ Alarm Clock


DoG MikkyW
January 1st, 2009, 02:48 AM
This is just an alrm clock I wrote in C++...


#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;

int main()
{
/*------------------------------------------------
-----------------Alarm Time Set-------------------
------------------------------------------------*/
int minute, hour;
cout<<"Please enter the hour which you wish"<<endl;
cout<<"to wake up at: "; cin>>hour;
cout<<"Please enter the minute that you wish"<<endl;
cout<<"to wake up at: "; cin>>minute;
cout<<"Thank You, carry on..."<<endl;
Sleep(3000);
/*------------------------------------------------
------------------End Alarm Set-------------------
------------------------------------------------*/


/*------------------------------------------------
-----------------Clock Time Set-------------------
------------------------------------------------*/
int seconds=0, minutes, hours;
cout<<"Welcome to the Alarm Clock Program"<<endl;
cout<<"\nWhat is the current hour: "; cin>>hours;
cout<<"What is the current minute: "; cin>>minutes;
/*------------------------------------------------
------------------End Clock Set-------------------
------------------------------------------------*/


/*------------------------------------------------
------This part deals with the clock counter------
------------------------------------------------*/
char beep, check;
beep=7;
for(seconds=0;seconds<=59;seconds--)
{
/*------------------------------------------------
----------Alarm Noise and Spacebar Reset----------
------------------------------------------------*/
while(hour==hours)
{
while(minute==minutes)
{
cout<<beep<<beep<<beep;
if(kbhit())
{
check=getch();
if(check==' ')
{
break;
}
else
{
cout<<"You have to press space!"<<endl;
}
}
break;
}
break;
}
/*------------------------------------------------
----------End of Alarm Noise Programming----------
------------------------------------------------*/
seconds++;
if(hours<=9){cout<<"0"<<hours<<":";}
else{cout<<hours<<":";}
if(minutes<=9){cout<<"0"<<minutes<<":";}
else{cout<<minutes<<":";}
if(seconds<=9){cout<<"0"<<seconds;}
else{cout<<seconds;}
Sleep(1000);
system("cls");
seconds++;
if(seconds==60)
{
seconds=0;
minutes++;
}
if(minutes==60)
{
minutes=0;
hours++;
}
if(hours==13)
{
hours=1;
}
if(kbhit())
{
char ch=getch();
if(ch==' '){break;}
}
}
/*------------------------------------------------
--------------End of clock counter----------------
------------------------------------------------*/
system("PAUSE");
return 0;
}

DoG MikkyW
January 1st, 2009, 02:49 AM
Additionally, I know it is very, very, non-portable, but it works for me, and that's what matters. It only works on windows, but give it a try, you might just like it. If anybody here knows C++, and has a question(there is some special, unique code smashing in there)just ask...

twenglish1
January 1st, 2009, 03:25 AM
interesting, i will definitely check it out, i just know a little c++ but i know enough to understand this code

EDIT: i just compiled it and tested it, and is it suppost to make noise, like beep or something, cause its not. and how would you make it so that when it gets to the time it activates another program

DoG MikkyW
January 1st, 2009, 02:49 PM
Hmmm, I could use some testers on this, because I just ran mine, entered 12:01 for wake up time, and 12:00 as time, I let it count up to 12:00:59, then when it hit 12:01:00, it beeped three times per second, not stopping until the spacebar is pressed.

Tell me what you did in your test, I might be able to help. And there are probably multiple ways to make it activate another program, for example, you could have it run a batch file that runs a program, so I'd assume you could probably run a program at the specified time.

twenglish1
January 1st, 2009, 09:28 PM
ok i set it to wake up at 9:25 and set the current time to 9:24, when it got to 9:25 the time started flashing but no beeping(yes my speakers are on, and turned up)and it kept counting up after 9:25 while still blinking

DoG MikkyW
January 2nd, 2009, 01:06 AM
Huh, blinking??? That's insane. What did you compile it with?

deathlord888
January 2nd, 2009, 01:21 AM
haha this is SO much easier in VB6

DoG MikkyW
January 2nd, 2009, 01:39 AM
Yes, but it's more difficult and takes way more learning in C++. Anyways, could somebody else compile and run it?

deathlord888
January 2nd, 2009, 01:47 AM
yes i would if i had a C++ compiler still haha

twenglish1
January 2nd, 2009, 02:51 AM
Huh, blinking??? That's insane. What did you compile it with?

the time was appearing and disappearing(blinking), and i used dev c++ cause it was all i had at the moment

DoG MikkyW
January 2nd, 2009, 01:39 PM
What OS are you running? I'm running windows vista home premium, I compiled with dev C++ as well. But mine runs perfectly.

twenglish1
January 2nd, 2009, 04:10 PM
im using windows xp professional

DoG MikkyW
January 2nd, 2009, 10:44 PM
Hmmmm, Maybe it doesn't work on xp. I don't know why though...

m00s3m4n
July 29th, 2009, 04:18 AM
Hey i love ur program!!!! umm i have recently begun the learning of C++ and i really like the language, but can i ask you what compiler you are using, cause im using DevC++ and it's pissing me off when my programs only flash a "DoS" prompt window...
Cheers, Nick.

twenglish1
July 29th, 2009, 12:21 PM
when you say it flashes in the Dos prompt do you mean the program opens and closes really fast, and doesn't do anything?

ishkur88
July 29th, 2009, 05:27 PM
add "cin.get();" to the end of the program.

or if you're a noob bitch, use "system('PAUSE');"

twenglish1
July 29th, 2009, 10:19 PM
i am a noob bitch i used "system('pause');"

DoG MikkyW
July 29th, 2009, 10:20 PM
Hey i love ur program!!!! umm i have recently begun the learning of C++ and i really like the language, but can i ask you what compiler you are using, cause im using DevC++ and it's pissing me off when my programs only flash a "DoS" prompt window...
Cheers, Nick.

add "cin.get();" to the end of the program.

or if you're a noob bitch, use "system('PAUSE');"

This is really old, but anyways. Yeah, I use DevC++ as well, fucking great compiler. Anyways, do what ishkur says. cin.get(); although using system("PAUSE"); doesn't make you a noob bitch, it's just merely bad practice, as it is OS specific. I now use cin.get(); in my C++ programs and Console.ReadKey(true); in C# programs. It's better practice.

Thanks for bringing this up, I've actually been looking for a decent alarm clock, and I forgot that I made one. I might update it a bit... I'll keep you posted.

m00s3m4n
July 30th, 2009, 05:20 AM
Thanks for your info.. btw i got that "necro posting" comment aswell.

m00s3m4n
July 30th, 2009, 05:23 AM
Yepp it's really annoying.

demonhunter2
August 11th, 2009, 11:07 AM
this worked perfectly for me!

DoG MikkyW
August 11th, 2009, 12:04 PM
Yup. I try.

ravenscar
August 11th, 2009, 01:27 PM
alarm clock...hmm.... why not go buy one?
if i got this wrong tell me

DoG MikkyW
August 14th, 2009, 11:43 PM
alarm clock...hmm.... why not go buy one?
if i got this wrong tell me

Do you have a computer? Ok, I'd assume so, now, if you didn't have an alarm clock, using one for your computer would work quite well. Meh, I'm to tired to destroy you on this one, just trust me, you're wrong.