问题如下:游戏"Totals"可以由任意数量的人玩。它以100为总数开始,每个玩家依次对该总数进行-20到20之间的整数位移。赢家是使总数等于5的玩家。只使用所给出的三个变量: total adjustment counter 这是我目前的代码:
#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语句中。如何确定浮点数是否有小数部分。
double
代替。(顺便说一下,@Chris和我意思相同) - Tom van der Woerdtdouble
有什么不同? - Oliver Charlesworthfloat
呢?明明只有整数相关的内容。 - Daniel Fischer