I need Help here

Feb 12, 2014 at 6:33am
Hello Group! I am new here and need help on this project, any one please help me.
When I Run it it give error.

#include<iostream>
#include<conio.h>
#include<stdio.h>
delay();
using namespace std;
int main()
{
int h,m,s;
for(h=1;h<=12;h++)
{
for(m=1;m<=60;m++)
{
for(s=1;s<=60;s++)
{
cout<<h<<":"<<m<<":"<<s;
delay(1000);
clrscr();
}
}
}
getch();
return 0;
}
Feb 12, 2014 at 7:33am
What error? You have to provide more information.
Feb 12, 2014 at 7:53am
It seems 'c' code.

Please give us what error you get.

And please tell us what your going to do this program?(Expected output).

Feb 12, 2014 at 1:53pm
@ak16
It seems 'c' code.

Where did you see any sign of C code??? (except the forth line)
#include<iostream>

cout<<h<<":"<<m<<":"<<s;

@alirezahusainy786
delay(); isn't allowed in C++ as I know (I use MVS10) (no explicit return type is not allowed for a function)
and besides delay(); doesn't take any parameters however you used it with an int variable.
and one more thing (here just a question, I don't mean anything) is delay in conio.h? If so disregard the question, if not where is it defined?
Last edited on Feb 12, 2014 at 1:55pm
Feb 12, 2014 at 2:10pm
@alirezahusainy786

If you wish to use a delay(1000), which I believe is allowing the program to sleep for a second, use #include <windows.h> , and add Sleep(1000); in place of your delay(1000). To clear the screen, add this routine.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void clrscr()
  {
   DWORD n;
  DWORD size;
  COORD coord = {0};
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
  GetConsoleScreenBufferInfo ( h, &csbi );
  size = csbi.dwSize.X * csbi.dwSize.Y;
  FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
  GetConsoleScreenBufferInfo ( h, &csbi );
  FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
  SetConsoleCursorPosition ( h, coord );
  }
Feb 13, 2014 at 6:01am
@alirezahusainy786

yes you can use sleep() instead delay(),its in c.

@JewelCpp

Only using this
1
2
iostream
cout<<


your code not become c++.
Feb 14, 2014 at 10:56am
Thanks from all of you friends, here I just wanted to make a display of Hour, Minute and Second on C++ when it displays the 1st second then it should clear screen and show the next second, that's what I want to do and I got errors:


@whitenite1 and ak16
I use CodeBlocks.
Feb 14, 2014 at 11:50am
and by the way I found this one, but I couldn't understand most of the codes mentioned there cause I am a new learner.
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <stdio.h>

#include <time.h>

#include <windows.h>

COORD coord = {0, 0};

void gotoxy (int x, int y)

{

    coord.X = x; coord.Y = y; // X and Y coordinates

    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

void delay(unsigned int mseconds)

{

    clock_t goal = mseconds + clock();

    while (goal > clock());

}

void showClock(int x_1, int x_2, int x_3,int y){

    long i = 0;                      /* Loop counter              */

    clock_t now = 0;                 /* Holds initial clock time  */

    int interval = 1;                /* Seconds interval for o/p  */

    int elapsed = 0;

    int min=0,MIN=0,hrs=0,sec=0;

    int d=0,f=0;

    now = clock();

    /* Get current clock time    */

    for(i = 0L ;  ; i++){

        elapsed = (clock()-now)/CLOCKS_PER_SEC;

        if(elapsed>=interval){

            interval += 1;

            if(elapsed%60==0){

                min=elapsed/60;

                d=60*min;

                if(min%60==0){

                    hrs=min/60;

                    f=60*hrs;

                }

            }

            sec=elapsed-d;

            MIN=min-f;

            if(hrs<10){

                gotoxy(x_1,y);printf("0%d",hrs);

            }else{

                gotoxy(x_1,y);printf(":%d",hrs);

            }

            if(min<10){

                gotoxy(x_2,y);printf(":0%d",MIN);

            }else{

                gotoxy(x_2,y);printf(":%2d",MIN);

            }

            if(sec<10){

                gotoxy(x_3,y);printf(":0%d",sec);

            }else{

                gotoxy(x_3,y);printf(":%2d",sec);

            }

        }

    }

}

int main()

{

    showClock(2,4,7,4);

 return 0;

}
Feb 14, 2014 at 12:23pm
Feb 14, 2014 at 2:48pm
@line 4 delay();

remove that line.
Feb 17, 2014 at 10:13am
@Jaybob
I removed that line. delay works on turbo C not in C++.
Feb 17, 2014 at 11:19am
C does not have function overloading. Therefore, if there is a function named "delay", there is exactly one function and in principle the compiler does not need to care about matching the parameter and return types; the linker will link calls to implementation -- or fail miserably.

C++ does have overloading and therefore the compiler has to know which functions contain name "delay" in order to choose the best type match. You have to declare the necessary functions properly and the #include directive helps in that; it makes declarations in header file visible.

"Turbo C" is one compiler implementation from one vendor, and it supports some features of some language. Compilers may not support all features of a language (standard), but they can support non-standard extensions too. Use of non-standard features bind you to specific platform (compiler/OS) and that is not a Good Thing.
Feb 21, 2014 at 3:49pm
Here I could fix it, A digital clock.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
int h,m,s;
    for(h=0;h<=12;h++)
    {
        for(m=0;m<=60;m++)
        {
            for(s=0;s<=60;s++)
            {
                cout<<h<<":"<<m<<":"<<s;
                Sleep(1000);
                system("cls");
            }
        }
    }
return 0;
}
Last edited on Feb 21, 2014 at 3:52pm
Topic archived. No new replies allowed.