怪物弹珠国服阿波罗x:然后让这个C程序可以按 X 键退出?

来源:百度文库 编辑:高校问答 时间:2024/05/05 14:22:36
这个程序会一直走下去, 如何让他可以按 X 键退出呢?

#include <stdio.h>
main()
{

float x, totaal = 0.0;
for (x =0.0; x != 0.9; x += 0.1)
{ /*slechtetest*/
totaal += x;
printf("x = %f,lopendtotaal= %f\n",x, totaal);
system("pause");
}
}

for (x =0.0; x != 0.9; x += 0.1)
循环条件写的有问题……
楼上说的有道理。

system("pause");应该替换为下面几行:
#include <conio.h>
...
if (kbhit())
{
char c=getch();
if (c=='X'||c=='x')
break;
}
...

for (x =0.0; x != 0.9; x += 0.1)
循环条件写的有问题……
是死循环把x != 0.9改成x<=0.9
system("pause");
按任意键可以退出!