Timer

I was trying to make a basic timer. It looked okay in theroy but when I ran it the hours went up at the speed the milliseconds should have. Why is it doing this? Thanks.

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
  #include <iostream>
#include <windows.h>

using namespace std;

int milliseconds;
int seconds;
int minutes;
int hours;

void newLine()
{
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
}

void center()
{
    cout << "                          ";
}

int main()
{
    while(true)
    {
        Sleep(100);
        ++milliseconds;
        if(milliseconds = 10)
        {
            seconds++;
            milliseconds = 0;
        }
        if(seconds = 60)
        {
            minutes++;
            seconds = 0;
        }
        if(minutes = 60)
        {
            hours++;
            minutes = 0;
        }
        newLine();
        center();
        cout << hours << " : " << minutes << " : " << seconds << "." << milliseconds;
    }
}
= is the assignment operator. == is the comparison operator. So you need to change
milliseconds = 10 to milliseconds == 10. Make a similar change on lines 32 and 37.

There are 1000 milliseconds in a second, not 10, so maybe something is named wrong?
Thanks, what a stupid mistake.
Topic archived. No new replies allowed.