...and as I'm sure Dave knows the problem with his "naive program" is that you could just let it sit there never pressing anything and it will never end. I would suggest using conio.h and kbhit()
Code:
#include <iostream>
#include <ctime>
#include <conio.h>
using namespace std;
int main() {
int press = 0;
time_t now, start = time(0);
while ( (now = time(0)) < start + 20 ) {
if (kbhit()) { // Wait for input
if (getch() == 13) { // Compare that input to Enter
cout << ++press << endl;
}
}
}
cout << "You hit ENTER " << press << " times.";
cin.get(); // You should put this in a check to see it isn't
// ENTER otherwise you pound your key into
// closing the program
return 0;
}