I am writing an alarm clock program in C++, and it works great for now, but I was wondering is there any way I can have the user select the sound they want to blare once it goes off.
If it helps, here is my code, as bloated as it may be:
#include <iostream>
#include <ctime>
#include <dos.h>
#include <time.h>
#include <stdio.h>
#include <Windows.h>
#include <Mmsystem.h>
#include <conio.h>
#include <unistd.h>
#pragma comment(lib, "winmm.lib")
using namespace std;
int main(){
// Figure out how to let them choose song
int backup;
int hours=0;
int minutes;
int seconds;
int remain;
time_t current;
struct tm * timeinfo;
int main;
TOGGLE1:
system("CLS");
cout<<"Console Alarm Clock v 2.0 beta 1"<<endl<<"Brown Beard the Pirate ©2010"<<endl<<endl<<endl;
cout<<"What time do you want to be woken up? (on the 24 hour clock)"<<endl;
cin>>backup;
TOGGLE2:
main = backup;
system("CLS");
cout<<"Console Alarm Clock v 2.0 beta 1"<<endl<<"Brown Beard the Pirate ©2010"<<endl<<endl<<endl;
while (main>60){
hours++;
main = main -100;
}
if (main<0){
cout<<"Invalid time!"<<endl;
goto TOGGLE1;
}
if (backup>2400){
cout<<"Invalid time!"<<endl;
goto TOGGLE1;
}
if (backup>1259){
cout<<"Clock set for "<<backup-1200<<" PM"<<endl;
}else{ if(backup>1300 && backup<1159){
cout<<"Clock set for "<<backup<<" PM"<<endl;
}else{
cout<<"Clock set for "<<backup<<" AM"<<endl;
}
}
minutes = hours*60+main;
seconds = minutes * 60;
time (¤t);
timeinfo = localtime (¤t);
int hour = timeinfo->tm_hour;
int min = timeinfo->tm_min;
int sec = timeinfo->tm_sec;
int timeleft = hour*3600+min*60+sec;
remain = seconds - timeleft;
while (remain !=0){
time (¤t);
timeinfo = localtime (¤t);
hour = timeinfo->tm_hour;
min = timeinfo->tm_min;
sec = timeinfo->tm_sec;
timeleft = hour*3600+min*60+sec;
remain = seconds - timeleft;
Sleep(1);
}
//Implement chosen song instead of just alarm.wav
PlaySound("alarm.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
string answer("");
ASK1:
cout<<"Do you want to reset the clock?"<<endl;
cin>>answer;
if (answer.compare("Yes") == 0||answer.compare("yes")==0||answer.compare("Y")==0||answer.compare("y")==0){
ASK2:
PlaySound(NULL, 0, 0);
cout<<"Same time?"<<endl;
cin>>answer;
if (answer.compare("Yes") == 0||answer.compare("yes")==0||answer.compare("Y")==0||answer.compare("y")==0){
goto TOGGLE2;
}else {if (answer.compare("No") == 0||answer.compare("no")==0||answer.compare("N")==0||answer.compare("n")==0){
goto TOGGLE1;
}else {
cout<<"Invalid answer!"<<endl;
goto ASK2;
}
}
}else {if (answer.compare("No") == 0||answer.compare("no")==0||answer.compare("N")==0||answer.compare("n")==0){
PlaySound(NULL, 0, 0);
int y;
cin>>y;
return 0;
}else{
cout<<"Invalid answer!"<<endl;
goto ASK1;
}
}
}