I'm trying to get this countdown to work. I'm trying to get it to countdown from 10 down to "Blast off", with Blast off being 0. Each output replaces the one before it. I'm very confused. 10 does not print, but 9 to Blast off do. When when it Blast off prints, it keeps printing. Does anyone know how I can print 10 and also print Blast off one time?
Please help!
Thanks!
#include <iomanip>
#include <iostream>
using namespace std;
#ifdef __GNUC__
#include <unistd.h>
#endif
#ifdef _WIN32
#include <cstdlib>
#endif
int main()
{
cout << "CTRL-C to exit...\n";
for (int tens = 10; tens > 0; tens--)
{
for (int units = 9; units < 10; units--)
{
cout << tens << '\r';
cout << ' ' << units;
if (units < 1)
cout << '\r' << "Blast off!\n";
cout.flush();
#ifdef __GNUC__
sleep(1); // one second
#endif
#ifdef _WIN32
_sleep(1000); // one thousand milliseconds
#endif
cout << '\r'; // CR
}
}
return 0;
} // main