stopwatch problem

I have to create a stopwatch program and I think I have it all finished and it runs without any errors. The problem that I am having is that I can't get the clock() function to store the time in beginTime and endTime. it keeps printing -858993460 for both values. i can't figure this out.
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
49
50
51
52
53
54
55
56
#ifndef __STOPWATCH__
#define __STOPWATCH__

#pragma warning(disable:4996)
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <iomanip>
using namespace std;

class StopWatch {
	private:
		clock_t beginTime;
		clock_t endTime;
		clock_t elapsedTime;
		bool stopped;


	public:
		StopWatch::StopWatch(){
			clock_t beginTime = (unsigned int)0;
			clock_t endTime = (unsigned int)0;
			clock_t elapsedTime = (unsigned int)0;
			bool stopped = true;
		}

		void StopWatch::Start(){
			if(stopped == true){
				stopped = false;
				beginTime = clock();
			}
			else if(stopped == false){
				cout << "The clock is already started" << endl;
			}
		}

		void StopWatch::Stop(){
			if(stopped == false){
				stopped = true;
				endTime = clock();
			}
			else if(stopped == true){
				cout << "The clock is already stopped" << endl;
			}
		}

		void StopWatch::DisplayTimerInfo(){
			cout << "The timer started: " << beginTime << endl;
			cout << "The timer ended: " << endTime << endl << endl;
			elapsedTime = endTime - beginTime;
			cout << fixed << setprecision(3);
			cout << elapsedTime << " seconds have passed." << endl;
		}
};
#endif 
Topic archived. No new replies allowed.