I'm just trying to write a program which outputs a series of numbers overwriting one another on the same line of the console screen. like 10 9 8 7 6 etc.
I'm using xcode and compiling in xcode. And this outputs "10 121469 121468", what am I doing wrong? Why doesn't it seem so obvious?
#include <iomanip>
#include <iostream>
using namespace std;
#ifdef __GNUC__
#include <unistd.h>
#elif defined _WIN32
#include <cstdlib>
#endif
int main()
{
cout << "Description: This program will show you how much change" << endl;
cout << "you will need to complete a transaction using a already" << endl;
cout << "specified denomination" << endl << endl;
cout << "CTRL=C to exit...\n";
for (int units = 10; units > 0; units--)
{
cout << units << ' ';
cout.flush();
#ifdef __GNUC__
sleep(1); //one second
#elif defined _WIN32
_sleep(1000); //one thousand milliseconds
#endif
cout << '/r'; // CR
}
return 0;
} //main