First, I remember learning a function in my first programming class to make a program wait before running the next bit of code. That was about 5 years ago, and I've completely forgotten it. I've found a way to do this, but I think there might be a more efficient way to do it (such as the function I was taught long ago).
Here's the way I found:
#include <iostream> using namespace std; #include <ctime> using namespace std; void delay( int ); int main() { cout << "Waiting 5 seconds before printing overused phrase...\n"; delay ( 5 ); cout << "Hello World!"; } void delay( int seconds ) { time_t currentTime1; //pre-defined variable for holding time time_t currentTime2; //pre-defined variable for holding time time ( ¤tTime1 ); //stores the current time in currentTime1 while ( currentTime2 <= (currentTime1 + seconds) ) { time ( ¤tTime2 ); //stores the current time in currentTime2 } }
This may not be the best way there is, but I'm sure one of you can point me in a better direction.
Secondly, (and I can't think of any way to do this) I need to be able to accept a single character of input from the keyboard without the user having to hit the return key afterward. I am asking yes or no questions and I want the user to be able to hit 'y' or 'n' and I don't want them to have to hit return to input the data. How is this done?
Thanks to everyone who gives me a hand!
Edited by Fealos, 23 May 2005 - 12:29 AM.