hey guys, i need some real bad help for my c++ project......i'm making an analog clock in C++ graphics.........n my clock works just fine, except for the fact that i haven't as yet added an hour hand, :rolleyes: and yeah..my minute hand runs almost as fast as my second hand.:lol:.....plzzzzzzzzzzzz get me outta this, i need ur help......:sad:
here's my program..........
p.s.-leave alone the initial few lines, they're just an intro, meant for my teacher..........
n yeah, guys, i'm in an indian school, in XI standard, so my project's supposed to be pretty easy........so plzzzzzzzz make corrections in my project while keeping it in my brain's reach.....all i ask is tht u guys keep it easy...........
this is my program.............

#include<iostream.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,i,j,x,a,b,c,d,e,f;
initgraph(&gd,&gm," ");
{
setcolor(4);
setbkcolor(0);
settextstyle(4,0,6);
for(a=0;a<=750;a=a+25)
for(b=0;b<=7;b++)
{
{
setcolor(b);
sound(100);
delay(50);
outtextxy(a,a,"COMPUTER PROJECT");
}
clearviewport();
}
for(c=0;c<=350;c=c+5)
for(d=0;d<=7;d++)
{
setcolor(d);
sound(50);
outtextxy(250,250,"made by kanika");
outtextxy(250,300,"and simran");
rectangle(260-c,400-c,200-c,250+c);
}
clearviewport();
{
for(f=0;f<=700;f=f+3)
for(e=0;e<=7;e++)
{
setcolor(e);
circle(360,250,f);
outtextxy(100,230,"AnAlOg ClOcK");
}
}
clearviewport();
nosound();
circle(290,250,200);
outtextxy(260,40,"12");
outtextxy(180,65,"11");
outtextxy(120,135,"10");
outtextxy(100,210,"9");
outtextxy(120,280,"8");
outtextxy(180,350,"7");
outtextxy(260,390,"6");
outtextxy(360,350,"5");
outtextxy(440,280,"4");
outtextxy(460,210,"3");
outtextxy(440,135,"2");
outtextxy(360,65,"1");
for(j=360;j>=0;j=j-5)
for(i=450;i>=0;i=i-5)
{
{
setcolor(4);
setbkcolor(0);
delay(50);
pieslice(290,250,i,i--,100);
setfillstyle(0,0);
floodfill(290,250,0);
circle(290,250,100);
{
delay(300);
pieslice(290,250,j,j--,50);
}
}
}
}
}
getch();

kanika

Recommended Answers

All 11 Replies

Since you're using non-standard headers, I think most people will have a hard time running your code. And without proper indentation, they'll have a hard time reading it.

To see if I'm understanding the code correctly, I'll repost part of it with comments:

// don't know what the loop conditions are for...
for(j=360;j>=0;j=j-5) 
{
  for(i=450;i>=0;i=i-5)
  {
    {
      setcolor(4);
      setbkcolor(0);
      delay(50); // does this sleep for 50ms?
      pieslice(290,250,i,i--,100); // draw second hand
      setfillstyle(0,0);
      floodfill(290,250,0);
      circle(290,250,100);
      {
        delay(300); // sleep again?
        pieslice(290,250,j,j--,50); // draw minute hand
      }
    }
  }
}

The problem is that you'll draw the minute hand every time you draw the second hand. You need to move the innermost block into the outer for loop (after the inner loop), then possibly readjust your loop conditions. Pseudo-code:

for(/* ... */)
{
  for( /* ... */ )
  {
    /* whatever to draw second hand goes here */
  }
  /* whatever to draw minute hand goes here */
}

That way the minute hand only gets updated when the second hand has gone all the way around. For the hour hand, do something similar with yet another loop encompassing these. ;)

hey thnx for tryin to help.............cant thnk u enuff
n here are the answers to ur queries......
// don't know what the loop conditions are for...(this one's for the pieslice function....scroll down n u'll c it rite after the commands for the clock's body.....this is solely to change the values so as to make the minute hand move)

for(j=360;j>=0;j=j-5) 
{
  for(i=450;i>=0;i=i-5)
  {
    {
      setcolor(4);
      setbkcolor(0);
      delay(50); // does this sleep for 50ms?(yeah......it does)
      pieslice(290,250,i,i--,100); // draw second hand
      setfillstyle(0,0);
      floodfill(290,250,0);
      circle(290,250,100);
      {
        delay(300); // sleep again?(this is to maintain a time gap between the second n minute hands)
        pieslice(290,250,j,j--,50); // draw minute hand
      }
    }
  }
}
commented: Yet another script kiddie speaker who cant use code tags -1

Indent your code and use [code] tags when you post, it'll make everyone happier. And it'll show you how what you posted and what I posted are different. ;)

hey leave tht plzzzzzzzzzz n help me get outta this mess i've landed in..........u temme how to correct this program....a few corrections that i made are as follows.....

#include<iostream.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,i,j,x,a,b,c,d,e,f;
initgraph(&gd,&gm," ");
{
setcolor(4);
setbkcolor(0);
settextstyle(4,0,6);
for(a=0;a<=750;a=a+25)
for(b=0;b<=7;b++)
{
{
setcolor(b);
sound(100);
delay(50);
outtextxy(a,a,"COMPUTER PROJECT");
}
clearviewport();
}
for(c=0;c<=350;c=c+5)
for(d=0;d<=7;d++)
{
setcolor(d);
sound(50);
outtextxy(250,250,"made by kanika");
outtextxy(250,300,"and simran");
rectangle(260-c,400-c,200-c,250+c);
}
clearviewport();
{

for(f=0;f<=700;f=f+3)
for(e=0;e<=7;e++)
{
setcolor(e);
circle(360,250,f);
outtextxy(100,230,"AnAlOg ClOcK");
}
}
clearviewport();
nosound();
circle(290,250,200);
outtextxy(260,40,"12");
outtextxy(180,65,"11");
outtextxy(120,135,"10");
outtextxy(100,210,"9");
outtextxy(120,280,"8");
outtextxy(180,350,"7");
outtextxy(260,390,"6");
outtextxy(360,350,"5");
outtextxy(440,280,"4");
outtextxy(460,210,"3");
outtextxy(440,135,"2");
outtextxy(360,65,"1");
for(j=360;j>=0;j=j-5)
for(i=450;i>=0;i=i-5)
{
{
setcolor(4);
setbkcolor(0);
delay(100);
pieslice(290,250,i,i--,100);
circle(290,250,100);
setfillstyle(0,0);
floodfill(290,250,0);
}
delay(6000);
pieslice(290,250,j,j--,50);
circle(290,250,150);
setfillstyle(0,0);
floodfill(290,250,0);
}
}
}
getch();

kanika
p.s.-will be real gratefull to u if you can help me further

Kanika, please use code tags. Your code is unreadable without indentation. It's been mentioned three times in this thread already. Some comments in the code to describe what sections do would be nice as well. And since it's currently 2:00 AM here, I'll look at it when I get up in the morning.

maybe by the time u do read it, i'll b gone.......but yes, thnx for trying to b of sum help.............
as for the indentations, m new here, joined ystrday, so i hav no idea how u do tht..........

#include<iostream.h>
 #include<graphics.h>
 #include<dos.h>
 #include<conio.h>
 void main()
 {
 int gd=DETECT,gm,i,j,x,a,b,c,d,e,f;
 initgraph(&gd,&gm," ");
 {
 setcolor(4);
 setbkcolor(0);
 settextstyle(4,0,6);
 for(a=0;a<=750;a=a+25)
 for(b=0;b<=7;b++)
 {
 {
 setcolor(b);
 sound(100);
 delay(50);
 outtextxy(a,a,"COMPUTER PROJECT");
 }
 clearviewport();
 }
 for(c=0;c<=350;c=c+5)
 for(d=0;d<=7;d++)
 {
 setcolor(d);
 sound(50);
 outtextxy(250,250,"made by kanika");
 outtextxy(250,300,"and simran");
 rectangle(260-c,400-c,200-c,250+c);
 }
 clearviewport();
 {
 
 for(f=0;f<=700;f=f+3)
 for(e=0;e<=7;e++)
 {
 setcolor(e);
 circle(360,250,f);
 outtextxy(100,230,"AnAlOg ClOcK");
 }
 }
 clearviewport();
 nosound();
 circle(290,250,200);
 outtextxy(260,40,"12");
 outtextxy(180,65,"11");
 outtextxy(120,135,"10");
 outtextxy(100,210,"9");
 outtextxy(120,280,"8");
 outtextxy(180,350,"7");
 outtextxy(260,390,"6");
 outtextxy(360,350,"5");
 outtextxy(440,280,"4");
 outtextxy(460,210,"3");
 outtextxy(440,135,"2");
 outtextxy(360,65,"1");
 for(j=360;j>=0;j=j-5)
 for(i=450;i>=0;i=i-5)
 {
 {
 setcolor(4);
 setbkcolor(0);
 delay(100);
 pieslice(290,250,i,i--,100);
 circle(290,250,100);
 setfillstyle(0,0);
 floodfill(290,250,0);
 }
 delay(6000);
 pieslice(290,250,j,j--,50);
 circle(290,250,150);
 setfillstyle(0,0);
 floodfill(290,250,0);
 }
 }
 }
 getch();

kanika
p.s.-will be real gratefull to u if you can help me further

Indentation is just using tabs or spaces to mark where blocks start and end. Look at the difference (btw, there's some comments I added too):

#include<iostream.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
void main() // should be int main()
{
  int gd=DETECT,gm,i,j,x,a,b,c,d,e,f;
  initgraph(&gd,&gm," ");
  { // why start a block here?
    setcolor(4);
    setbkcolor(0);
    settextstyle(4,0,6);
    for(a=0;a<=750;a=a+25)
      for(b=0;b<=7;b++)
      {
        { // why create a block here?
          setcolor(b);
          sound(100);
          delay(50);
          outtextxy(a,a,"COMPUTER PROJECT");
        }
        clearviewport();
      }
    for(c=0;c<=350;c=c+5)
      for(d=0;d<=7;d++)
      {
        setcolor(d);
        sound(50);
        outtextxy(250,250,"made by kanika");
        outtextxy(250,300,"and simran");
        rectangle(260-c,400-c,200-c,250+c);
      }
    clearviewport();
    { // why create a block here?

      for(f=0;f<=700;f=f+3)
        for(e=0;e<=7;e++)
        {
          setcolor(e);
          circle(360,250,f);
          outtextxy(100,230,"AnAlOg ClOcK");
        }
    }
    clearviewport();
    nosound();
    circle(290,250,200);
    outtextxy(260,40,"12");
    outtextxy(180,65,"11");
    outtextxy(120,135,"10");
    outtextxy(100,210,"9");
    outtextxy(120,280,"8");
    outtextxy(180,350,"7");
    outtextxy(260,390,"6");
    outtextxy(360,350,"5");
    outtextxy(440,280,"4");
    outtextxy(460,210,"3");
    outtextxy(440,135,"2");
    outtextxy(360,65,"1");
    for(j=360;j>=0;j=j-5)
      for(i=450;i>=0;i=i-5)
      {
        { // why create a block here?
          setcolor(4);
          setbkcolor(0);
          delay(100);
          pieslice(290,250,i,i--,100);
          circle(290,250,100);
          setfillstyle(0,0);
          floodfill(290,250,0);
        }
        delay(6000);
        pieslice(290,250,j,j--,50);
        circle(290,250,150);
        setfillstyle(0,0);
        floodfill(290,250,0);
      }
  }
}
getch(); // this isn't even in main()

Now, could you restate the prbblems you currently have? I can't run your program because of the headers you're using, but I'll try to help out again...

[edit:] Ok, I just noticed you didn't even put the code tags on your last post. Before I even consider helping you again, you need to learn to use them. It's really easy. When you post your code, you put [code] before it and [/code] after it. That will preserve the indentation when you copy your source and paste it in the post window. Using them is part of the rules of the forum, so you'd better start using them.

you kno what?those blocks sure were all set up in the wrong places............my teacher told me today..........plus he's helping me out with my project, i just discovered i was heading the wrong way all through........and yeah, the nested loops you suggested were a solution to my problem...........so thanks bunches for all your support.........and yes, sorry for disturbing you that day at 2:00AM.........didn't know what time it was there because in india, it was 3 in the afternoon..........anyway thanks a lot..............;)

as for the indentations, m new here, joined ystrday, so i hav no idea how u do tht..........

So read the information from my post! I tried to help you with all of that. And I'm going to add this to the list...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.