hi

i need a program that set the clock to 00:00:00 if the user not enter the clock
then the program should count the time and print it on the screen until reach the user input

for example:
the time is 12:44:6 a.m.
and the user enter 4:3:50 a.m. to wake up
the program should count and print the clock from 12:44:6 a.m. until 4:3:50 a.m.

the output as follow
12:44:6
12:44:7
12:44:8
12:44:6
12:44:9
12:44:10
12:44:11
12:44:12
.
.
.
.
.

4:3:50

i really want your help

thanx

Recommended Answers

All 2 Replies

this might b helpfut for you

/* clock example: countdown */
#include <stdio.h>
#include <time.h>

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

int main ()
{
  int n;
  printf ("Starting countdown...\n");
  for (n=10; n>0; n--)
  {
    printf ("%d\n",n);
    wait (1);
  }
  printf ("FIRE!!!\n");
  return 0;
}

>this might b helpfut for you
Perhaps if your program is the only one running on the machine. A busy loop like the one in your wait function is a terrible CPU hog. Seeing as how the OP's program really only does two trivial things once per second (print the time and check if it needs to stop), there's a ton of wasted effort on doing nothing.

A much better option is to use a system-specific solution to pause the thread/process so that other programs can do something in the intervening time. For example:

#include <iostream>
#include <windows.h>

int main()
{
  while ( true ) {
    std::cout<<"One second has passed\n";
    Sleep ( 1000 );
  }
}
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.