C
cdrsir
maybe the title is a too big question, actually I just have a small
problem, see following codes:
*********************************************************************************
#include <iostream>
#include <windows.h>
#define OneSecond 1000
using namespace std;
int main()
{
int totalTime = 60; //seconds
cout<<"Please input a char within 60 seconds"<<endl;
char ch = NULL;
bool flag = true;
while ( flag ) {
/*task 1:
show the left time on the sreen
*/
cout<<"\rYou still have "<<totalTime--<<" seconds"
<<" to input a char:";
if(totalTime<=0) {
cout<<"\nTime Out!"<<endl;
flag = false;
}
/*take 2:
get a char from the user
*/
cin>>ch;
if(ch) flag = false;
// wait one second
Sleep(OneSecond);
}
cout<<"You have input the char "<<ch<<endl;
return 0;
}
*********************************************************************************
So I want the left time printed on the screen every seconds, at the
same time, the programm waits a input, how to do this?
I can only have seconds when the line with "cin>>ch;" commented. But
then I can not get any more input.
problem, see following codes:
*********************************************************************************
#include <iostream>
#include <windows.h>
#define OneSecond 1000
using namespace std;
int main()
{
int totalTime = 60; //seconds
cout<<"Please input a char within 60 seconds"<<endl;
char ch = NULL;
bool flag = true;
while ( flag ) {
/*task 1:
show the left time on the sreen
*/
cout<<"\rYou still have "<<totalTime--<<" seconds"
<<" to input a char:";
if(totalTime<=0) {
cout<<"\nTime Out!"<<endl;
flag = false;
}
/*take 2:
get a char from the user
*/
cin>>ch;
if(ch) flag = false;
// wait one second
Sleep(OneSecond);
}
cout<<"You have input the char "<<ch<<endl;
return 0;
}
*********************************************************************************
So I want the left time printed on the screen every seconds, at the
same time, the programm waits a input, how to do this?
I can only have seconds when the line with "cin>>ch;" commented. But
then I can not get any more input.