-
Reprinting a line
Hello All...
I am writting a program and I am using a count down in it and I was just wondering how I could rewrite a line instead of getting a new line every time a second passes.
This is the output I get now:
"Remaining Time: 10"
"Remaining Time: 9"
"Remaining Time: 8"
and do on
I would like:
"Remaining Time: <Have just this number change instead of a whole new line>"
Here is the count down code I am using:
Code:
#include <iostream.h>
#include <unistd.h>
int main()
{
int count = 10;
do
{
cout<<"Remaining Time: "<<count<<endl;
count = count - 1;
sleep(1);
}
while(count > 0);
}
Really Appreciate The Help!
-
You could try gotoxy(), more info in the FAQ.
-
Code:
#include <iostream.h>
#include <unistd.h>
int main()
{
int count = 10;
cout<<"Remaining Time: ";
do
{
cout <<count;
count = count - 1;
sleep(1);
system("CLS");
}
while(count > 0);
}
-
For Unix...
The CLS is a good (using CLEAR for unix)... that works but does anyone know or a way to do that without having to clear the entire screen?
-
Probably going against every standard known to man, but what about something along the following lines?
Code:
#include <stdio.h>
#include <conio.h> //included for clrscr, clear the screen however you like
#include <dos.h> // included for sleep on my DOS compiler
int main ()
{
clrscr();
int count = 10;
do
{
printf ("\r Remaining time: %i ",count);
count = count -1;
sleep(1);
}
while (count > 0);
return 0;
}
No reason you couldn't use cout with "\r" I guess, for some reason my fingers wanted printf.