Help Please adding a counter to my Program

This is a discussion on Help Please adding a counter to my Program within the C++ Programming forums, part of the General Programming Boards category; Im having problems implementing the time.h in order to include a time feature into my program. This is how it ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Help Please adding a counter to my Program

    Im having problems implementing the time.h in order to include a time feature into my program. This is how it stands at the moment. I've only been using c++ since september so im still rather new to it. Any Help would be much appriciated

    Code:
    #include <stdio.h>
    #include <graphics.h>
    #include <math.h>
    
    
    using namespace std;
    
    char scoretext[20];
    int score = 0;
    
    void button(int x,int y);
    void rectangle( int left, int top, int right, int bottom );
    
    int main(int argc, char *argv[])
    
    {
        int tag = -1;
        int i=69,j=239,delay,xdir=1,ydir=1;
        signed int x2,y2;
        int distance,oldi,oldj,k;
        initwindow(540,500);
        
    
        setcolor (LIGHTGREEN);
        rectangle (4,4,536,416);
       
        setcolor (LIGHTBLUE);
        rectangle (8,8,532,412);
        printf("Score = %d",score);
    
        int btns[] = {150, 45, 430, 350, 250, 250, 500, 150, 75, 150, 100, 370, 350, 100};
        int num_btns = 7;
        
      
        while(1)
        {
        
        
        
        button(btns[0],btns[1]);
        button(btns[2],btns[3]);
        button(btns[4],btns[5]);
        button(btns[6],btns[7]);
        button(btns[8],btns[9]);
        button(btns[10],btns[11]);
        button(btns[12],btns[13]);
        
        //Edge detections, these are the walls of the box 
        
            oldi=i;
            oldj=j;
            if (i>=522) 
            {xdir = -(rand()%2)-1; }
            
            
            if (i<=20)
            {xdir = (rand()%2)+1; }
            
            i=i+xdir;
            
            
            if (j>=402)
            {ydir = -(rand()%2)-1;}
            
            
            if (j<=20)
            {ydir = (rand()%2)+1;}
            
            j=j+ydir;
            
        
            
        //Collision Detect   
            
            for(k=0;k<(num_btns * 2);k=k+2)
            { 
                x2=btns[k]-i;    
                y2=btns[k+1]-j; 
    
                distance=(int)sqrt((float)(x2*x2)+(y2*y2));
                
                if((distance<20) && (tag == -1))
                {
                tag = k;
                    score = score+10;
                    printf("Score = %d",score);
                    sprintf(scoretext,"Score = %d",score);
                    setcolor(LIGHTBLUE);
                    settextstyle(4,0,2);
                    outtextxy(10,425,scoretext);
                
                               
                    if (ydir>=1 && xdir>=1) 
                    {xdir = -1;}
                    
                    
                    else
                    if (ydir>=1 && xdir<=-1) 
                    {xdir = 1;}
                    
                    
                    else
                    if (ydir<=-1 && xdir>=1) 
                    {ydir = 1;}
                    
                    
                    else
                    if (ydir<=-1 && xdir<=-1) 
                    {ydir = 1;}
                    
                    
                }
          
          if ((distance >80)&&(tag ==k))
          { tag = -1;}
          }
          
            
          
          setcolor(BLACK);
          setfillstyle(1,BLACK);
          fillellipse(oldi,oldj,10,10);
         
         setfillstyle(1,LIGHTBLUE); 
         fillellipse(i,j,10,10);
         for(delay=0;delay<250000;delay++);
            //getch();
          
     
           
        }
        
        
        closegraph();
        return 0;
    }
    
    
    
    void button(int x,int y)
    {
        int i;
        i=y;
        
        setcolor(LIGHTGREEN);
        setfillstyle (SOLID_FILL, LIGHTGREEN);
        fillellipse(x,y,10,10);
        
        //setcolor(SOLID_LIGHTGREEN);
        //fillellipse(x,y,5,5); 
        
    }

  2. #2
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149
    Could you further explain what you mean by adding a counter. Are you just wanting to time how long the program ran or something else?
    Also, what specific problems are you having implementing it?
    IDE - Visual Studio 2005
    Windows XP Pro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. guidence to a program C
    By nurofen in forum C Programming
    Replies: 17
    Last Post: 04-15-2008, 12:50 AM
  2. Adding program to startup
    By VeX92 in forum C++ Programming
    Replies: 4
    Last Post: 10-28-2007, 02:08 AM
  3. Replies: 2
    Last Post: 10-23-2004, 04:46 AM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 08:51 AM
  5. Syntax for adding a program to autoexec.bat...
    By Sebastiani in forum C Programming
    Replies: 5
    Last Post: 06-18-2002, 01:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21