这里是问题:游戏总数可以由任何人玩。它总共从100开始,每个玩家依次在-20和20之间产生一个整数位移。获奖者是其调整使得总等于5只使用三个变量给出的球员: 总 调整 计数器 这里是我到目前为止有:确定一个浮点数是否有小数部分?
#include <stdio.h>
int main (void)
{
int counter=0;
float adj;
int ttl=100;
printf("You all know the rules now lets begin!!!\n\n\nWe start with 100. What is\n");
while (ttl!=5)
{
printf("YOUR ADJUSTMENT?");
scanf("%f",&adj);
counter++;
if (adj<=20 && adj>=-20)
{
ttl=ttl+adj;
printf("The total is %d\n",ttl);
}
else
{
printf ("I'm sorry. Do you not know the rules?\n");
}
}
printf("The game is won in %d steps!",counter);
}
我需要: 当输入十进制数字后转到else。我如何确定浮动是否有小数部分。
在二进制级别上,浮点数没有小数。 http://en.wikipedia.org/wiki/IEEE_754-2008 – 2011-12-18 02:13:22
我们在这里讨论漂浮物。它总是“有一个小数”。改为使用“double”。 (FYI @Chris和我的意思是一样的) – 2011-12-18 02:13:54
@TomvanderWoerdt:'double'有什么区别? – 2011-12-18 02:14:53