These is my code and i need to change it so that the second out put replaces the first and so on.

#include <iostream>
#include <stdlib.h>


using namespace std;

int main()
{
 int a = 0;
 int h;
 int m;
 int s;

 mistake:

 cout << "What is the current hour?\n";
 cin >> h;

 cout << "\nWhat is the current minute?\n";
 cin >> m;

 cout << "\nWhat is the current second?\n";
 cin >> s;

 if (h > 24 || m > 60 || s > 60)
  {
  cout << "\nPlease try again!\n\n";
  goto mistake;
  }

 system("clear");

 while (a == 0)
  {
  cout << h << ":" << m << ":" << s <<endl;
  sleep(1);
  system("clear");
  s++;
  if (s > 59)
   {
   s = 0;
   m++;

   if (m > 59)
    {
    m = 0;
    h++;

    if (h > 24)
     {
     h = 0;
     }
    }
   }
  }
 return 0;
}

so does any one have any idea?

A little more information would be appreciated, what exactly do you want changed? What exactly is the problem?

well i cant figure out how to make it so that the out put doesn't just keep clearing its self than going down the screen and then outputting something new exp:


output

output


output


output


and so on can you help?please.

Hello,
I would like to know which Operating System you are actually using.

For example if you are using a windows based operating system and the command prompt the command for the clear screen is

system(cls);

Where as for some other operating systems it is

system(clear);

So if you are using the current program on a windows operating system the output will move down so for windows try this

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
 int a = 0;
 int h;
 int m;
 int s;

 mistake:

 cout << "What is the current hour?\n";
 cin >> h;

 cout << "\nWhat is the current minute?\n";
 cin >> m;

 cout << "\nWhat is the current second?\n";
 cin >> s;

 if (h > 24 || m > 60 || s > 60)
  {
  cout << "\nPlease try again!\n\n";
  goto mistake;
  }

 system("cls");

 while (a == 0)
  {
  cout << h << ":" << m << ":" << s <<endl;
  sleep(1);
  system("cls");
  s++;
  if (s > 59)
   {
   s = 0;
   m++;

   if (m > 59)
    {
    m = 0;
    h++;

    if (h > 24)
     {
     h = 0;
     }
    }
   }
  }
 return 0;
}

I hope this solves your problem

I would also add in that if you want to use the sleep function in windows you will have to write in this . Sorry i was not able to edit my previous post.

#include <iostream>
#include <stdlib.h>
#include <windows.h>
using namespace std;

int main()
{
 int a = 0;
 int h;
 int m;
 int s;

 mistake:

 cout << "What is the current hour?\n";
 cin >> h;

 cout << "\nWhat is the current minute?\n";
 cin >> m;

 cout << "\nWhat is the current second?\n";
 cin >> s;

 if (h > 24 || m > 60 || s > 60)
  {
  cout << "\nPlease try again!\n\n";
  goto mistake;
  }

 system("cls");

 while (a == 0)
  {
  cout << h << ":" << m << ":" << s <<endl;
  Sleep(1000);
  system("cls");
  s++;
  if (s > 59)
   {
   s = 0;
   m++;

   if (m > 59)
    {
    m = 0;
    h++;

    if (h > 24)
     {
     h = 0;
     }
    }
   }
  }
 return 0;
}

The following changes::

#include <windows.h>

is to be added
and

Sleep(1000);

The S in sleep has to be made capital as C++ Is case Sensitive.

Hope this helped

First, get rid of the clear screen stuff since you cannot make it portable and is not part of standard C++
Second, get rid of the GOTO statement and use a while loop instead
Third, you say you want the "second out put replaces the first" so change your output statement to cout << h << ":" << m << ":" << s '\r' <<ends; \r will move the cursor to the beginning of the line just output.
ends is the same as endl except it does not go to the next line. It basically just forces the output to the screen.

hey ow would you make the while loop cause every time i try to use what u said with my program but it wont output the result by the way im using mac osx.

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.