本来是要ESC停止,Q暂停,R继续,但为什么这个程序在暂停之后,除了ESC任何键都能继续运行
#include<iostream>
using namespace std;
#include<conio.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
#define ESC 0x1b
#define Q 0x71
#define R 0x72
void loop (void);
int main()
{
loop();
return 0;
}
void loop(void)
{
int w,seed=1;
char i,j;
while(1)
{
if(kbhit()==0)
{
srand(seed);
w=rand()%100;
cout<<w<<endl;
seed=rand()+time(NULL)%1000;
Sleep(100); //产生随机数
}
else
{
i=getch();
if(i==ESC) //ESC停止
exit(0);
else if(i==Q)
{
if(w<=50)
cout<<"小"<<endl;
else
cout<<"大"<<endl;
j=getch(); //Q 暂停
if(j==R)//R继续
loop();
else if(j==ESC) //ESC停止
exit(0);
}
}