1 Replies - 8804 Views - Last Post: 12 May 2010 - 09:54 PM Rate Topic: -----

#1 Guest_Guest*


Reputation:

Creating a clock in Dev C++

Posted 12 May 2010 - 09:24 PM

Why hello there. As the title implies, I'm trying to create a clock in Dev C++. It works fine but I don't want the cout<<hour<<":"<<minutes<<":"<<n<<endl; part to keep displaying. I want the seconds, minutes, and hours to iterate accordingly but I don't want the cout statement to keep repeating itself. What can I do to fix this?

#include <stdio.h>
#include <time.h>
#include<iostream>

using namespace std;

void wait ( int seconds )
{
  clock_t endwait;
  endwait = clock () + seconds * CLOCKS_PER_SEC ;
  while (clock() < endwait) {}
}

int main ()
{
  int n;
  int minutes = 0; 
  int hours = 0; 
  
  printf ("Starting countdown...\n");
  for (n=0; n<=60; n++)
  {
    //printf ("%d\n",n);
    
    wait (1);
    if(n == 60)
    {
         minutes += 1;
         n = 0;
    }
    if(minutes == 60)
    {
         hours += 1;
    }
    
    cout<<hours<<":"<<minutes<<":"<<n<<endl; 
    
  }
  printf ("FIRE!!!\n");
  system("pause");
  return 0;
}



Is This A Good Question/Topic? 0

Replies To: Creating a clock in Dev C++

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Creating a clock in Dev C++

Posted 12 May 2010 - 09:54 PM

Use the Windows API to set the cursor position. Move the cursor around to overwrite the displayed numbers as needed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1