#include <stdio.h>
//#include <conio.h> //consoleinput/output kbhit()\getch()
#include <Windows.h>
int count = 0; //不停变换的数字
int running= 1;//是否正在运行
int start = 0; //是否开始
//多线程处理函数
DWORD WINAPI MyProc(LPVOID lpParam)
{
while(running)
{
if(start)
{
printf("%d",count = (count + 1) % 10);//让count的值保持在0-9之间
printf("\b");//让光标退一格http://www.jiakang021.com
}
Sleep(50);
}
return0;
}
int main()
{
inti = 0;
intaNum[4]; //保存4个幸运数字
intiluck; //幸运值
intadd, mul; //加,乘
HANDLEhThread;
hThread= CreateThread(NULL, 0, MyProc, NULL, 0, NULL);
CloseHandle(hThread);
printf("---------测试你今天的幸运值-----------\n");
printf("请按空格键开始和停止:\n");
while(i< 4)
{
if(kbhit()&& getch() == ' ')//如果我们按下了键并且该键是空格键 //逻辑运算符&& 且 ||或
{
start= !start;//取非运算符!原来的值为真,让它变成假,原来是假,让它变成真
if(start)
{
printf("[%d->",i + 1);
}
else
{
printf("%d]",count);
aNum[i++]= count; //保存该幸运数字到数组当中
}
}
}
running= 0; //让子线程退出释放
printf("\n你的幸运数字是:");
//计算运气值
add= mul = 0;
for(i= 0; i < 4; i++)
{
printf("%d",aNum[i]);
add+= aNum[i]; //累加数组中的数字
}
printf("\n");
mul= add;
while(add>= 10)
{
add= add / 10 + add % 10;//add = 45 ---> add = 9
}
while(mul>= 10)
{
mul= add / 10 * (add % 10);//add = 45 ---> add = 20-----> add = 0
}
printf(",你的运气值为:%d\n",add * 10 + mul);
getch();//让程序停留在此
return0;
}