Hello. I'm trying to write a program witch asks you to write delay and then counts time left. But it's not working how it should. If i write number 9 or less it's working fine. But if i write number 10 or more it prints numbers wrong, ex. ir write 12, then program writes numbers like this: 12,11,10,90,80,70,60,50,40,30,20,10,00. Here's code:

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

int main () {
	int delay;
	cout << "Enter delay: ";
	cin >> delay;
	cout << "Time left: ";
	for (delay; delay>=0; delay--) {
		if (i >= 9) 
			cout << "\b";
		cout << "\b" << i;
		Sleep (1000);
		if (i == 0) {
			cout << endl << "Time over.\n";
		}
	}
	cin.get();
	return 0;
}

What am i doing wrong?
Sorry for my bad english. Hope you understood.

#include <iostream>
#include <windows>

int main ()  {
   int del;
   std::cin >> del;
   for (del;del>=0;del--)  {
      std::cout <<  del;
      Sleep(1000);
      std::cout << "\b\b\b\b\a";
    }
 }

Ok. This works fine. But i can't add any tekst to it...

Edited 6 Years Ago by fire_: n/a

#include <windows>
#include <string>
#include <iostream>
#include <sstream>

int main ()  {
   std::string text="countdown: ";
   int del;
   std::cin >> del;   
   for (del;del>0;--del)  {
     std::ostringstream o;
     o << text << del;
     std::string count(o.str().size(),'\b');
     count+="\a";
     std::cout << o.str();
     Sleep(1000);
     std::cout << count;
   }
 }
#include <stdio>
#include <stdlib>
#include <windows>

int main ()  {
   int del;
   scanf("%i",&del);
   for (del;del>=0;del--)  {
      printf("Countdown :%d\r\a",del);
      fflush(stdout);
      Sleep(1000);
    }
 }

Maybe someone could sprinkle some clarity upon us ..

This article has been dead for over six months. Start a new discussion instead.