Friday, July 31, 2009

How to clear all the text when loop in C++?

yeh thank you too all i've figure out looping but in annoyed of the text when im ask to try again. is there any way to clear the past data and like reset the whole thing when in loop?


here's my source code pls help agian.








#include %26lt;iostream%26gt;


using namespace std;


int main ()


{


char answer;


int temperature, pressure;





cout%26lt;%26lt; "Would you like to test the temp? y/n \n";


cin%26gt;%26gt;answer;





while (answer=='y' || answer=='Y')


{


cout%26lt;%26lt; "Input temperature: \n";


cin%26gt;%26gt;temperature;


cout%26lt;%26lt; "Input pressure: \n";


cin%26gt;%26gt;pressure;





if (temperature%26gt;100 || pressure%26gt;200)


{ cout%26lt;%26lt;"Warning End of The World. \n" ;


}





else


{


cout%26lt;%26lt;"It's Fine. \n" ;


}


cout%26lt;%26lt; "Would you like to test the temp again? y/n \n";





cin%26gt;%26gt;answer;





}//ends while loop





return 0;





}

How to clear all the text when loop in C++?
Yes, and this should do nicely.





/** simple screen clearing function **/


void myClearScreen(int lines)


{


while (lines--)


cout %26lt;%26lt; endl;


}








//use it like so


int main()


{





// To clear the "usual" 25 line screen:


myClearScreen(25);





//Very flexible ... maybe you just want to push a few lines up:


myClearScreen(7);





return 0;


}





/////// I would put it here in your code:


cout%26lt;%26lt; "Would you like to test the temp again? y/n \n";


cin%26gt;%26gt;answer;


if(answer == 'y' || answer == 'Y' )


myClearScreen(50);
Reply:Unfortunately, there is on standard way to clear a terminal screen in C/C++. You'll have to use OS specific and library dependant methods. Here's a site that gives you some instructions on how to do it in Linux and Windows.





http://www.irule.be/bvh/c++/howto_portab...


No comments:

Post a Comment