0

How not to print "Time Remaining" every time in dev c++ , I want to print "Time Remain : 59" then 59 removed and put 58 and so.

#include <iostream> #include <Windows.h> using namespace std; int main(){ int counter = 60 ; Sleep(1000); while (counter>=1){ cout<<"Time Remaining : " << counter << endl; Sleep(1000); counter--; } return 0; }//main //Output is... // Time Remaining : 60 /*Time Remaining : 59 ...and so on but I dont want this output format I want this Time Remaining : 60 then 59 replaces the number 60 directly on it's location // I used Dev c++ as my IDE */ Appreciate ur help guys , please help

2nd May 2021, 10:37 PM
DataStream Cowboy
DataStream Cowboy - avatar
2 Respostas
+ 2
you can simply add system("cls"); right at the start of the loop to clear the screen every time before printing. Use the header #include<stdlib.h> #include <iostream> #include <windows.h> #include<stdlib.h> using namespace std; int main(void){ int counter = 60 ; Sleep(1000); while (counter>=1){ system("cls"); cout<<"Time Remaining : " << counter; Sleep(1000); counter--; } } I also tried implementing it using "\b" but for some unknown reason i got 60, 59, 58,.....13, 12, 11, 10, 90, 80, 70, 60.... An extra 0 was appended at the last #include <iostream> #include <windows.h> using namespace std; int main(void){ int counter = 60 ; cout<<"Time Remaining : "; while (counter>=1){ cout<< counter; Sleep(100); if(counter>9) cout<<"\b\b"; else cout<<"\b"; counter--; } }//main I hope this helps
3rd May 2021, 1:49 AM
Swoniga Maharjan
Swoniga Maharjan - avatar
4th May 2021, 4:49 PM
DataStream Cowboy
DataStream Cowboy - avatar