digital clock

Getting a compilation error; It says ''reloj'' is undeclared (first use this function). expected ; before ''reloj'' 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
    #include<iostream>
    #include<Windows.h>

    using namespace std;
    struct time
    {
    int hr,mint,seg;
    };

    int main()
    {
    time reloj[];
    reloj.hr = 0;
    reloj.mint = 0;
    reloj.seg = 0;
    for(int i = 0; i<24; i++)
    {
    if(reloj.hr == 23)
    {
    reloj.hr = 0;
    }
    for(int j = 0; j<60; j++)
    {
    if(reloj.mint == 59)
    {
    reloj.mint = 0;
    }
    for(int k = 0; k<60; k++)
    {
    if(reloj.sec == 59)
    {
    reloj.sec = 0;
    }
    cout<<reloj.hr<<" : "<<reloj.mint<<" : "<<reloj.sec<<endl;
    reloj.sec++;
    Sleep(1000);
    system("Cls");
    }
    reloj.mint++;
    }
    reloj.hr++;
    }
    }


Line 12 is declaring an array of time objects, not just one object. If you're only trying to make one time object named reloj, remove the square brackets [].
deleted it and I get the same build messages:

expected ; before reloj
statement is a reference, not call, to funcion 'time'
statement has no effect
''reloj'' is undeclared (first use this function)
Each undeclared identifier is reported only once for each function it appears
Have you changed anything else in the code? I also see some typos in the bottom part of the code where you say reloj.sec instead of reloj.seg.
Here is the code with the square brackets and the typos removed. The biggest thing to notice is the addition of whitespace at the beginning of the lines to make the code more easy to read. It is easier to tell what each loop encompasses if you use proper indentation.
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
#include<iostream>
#include<Windows.h>

using namespace std;
struct time
{
    int hr,mint,seg;
};

int main()
{
    time reloj;
    reloj.hr = 0;
    reloj.mint = 0;
    reloj.seg = 0;
    for(int i = 0; i<24; i++)
    {
        if(reloj.hr == 23)
        {
            reloj.hr = 0;
        }
        for(int j = 0; j<60; j++)
        {
            if(reloj.mint == 59)
            {
                reloj.mint = 0;
            }
            for(int k = 0; k<60; k++)
            {
                if(reloj.seg == 59)
                {
                    reloj.seg = 0;
                }
                cout<<reloj.hr<<" : "<<reloj.mint<<" : "<<reloj.seg<<endl;
                reloj.seg++;
                Sleep(1000);
                system("Cls");
            }
            reloj.mint++;
        }
        reloj.hr++;
    }
}
Last edited on
still gives me the 2 errors I posted before!.
Last edited on
What are those square brackets doing after time rolej[] ?
Topic archived. No new replies allowed.