My little program crashed..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<time.h>
using namespace std;

class Time {
public:
Time();
void setalarm(time_t);
void wait(int);
private:
int sec;
time_t current_time;
};

Time::Time()
{
current_time = time(0);
cout<<"Current time is: "<<current_time<<endl;
setalarm(current_time);
}

void Time::setalarm(time_t)
{
cout<<"Please set the alarm time(within 60 seconds):";
int a;
cin>>a;  
sec = (a>5 && a<=60) ? a:60;
for (int i = sec; i>0 ; --i)
{
cout<<i<<endl;
wait(1);
}
cout<<"Alarm!!\a"; 
}

void Time::wait(int seconds)
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}


int main()
{
Time A;
system("pause");
}


(1)The program run normally until the word "Alarm!!". It gives no sound("\a") and the PC crahed totally. I would know how to fix the problem. (I directly copy the Wait function from this website).
(2) Despite searching on the net and making multiple tries, I still cannot get Line 18 into a standard calendar (i.e. Year, Month, Date, Hour, Minute, Second). Can someone show me an example of doing this?

Thanks!
the ctime function converts from time_t to a string, but not in that format
Topic archived. No new replies allowed.