我寫了這個代碼:代碼錯誤或?用C
float suma;
int centy;
int cele;
printf("Zadaj sumu a ja ti ju napisem a zaroven aj vysklonujem:\n");
scanf("%f",&suma);
cele=(int)suma;
centy= (suma-cele)*100;
switch ((int)suma) {
case 1:
printf("%d euro",(int)suma);
break;
case 2 ... 4:
printf("%d eura",(int)suma);
break;
default:
printf("%d eur",(int)suma);
break;
}
switch (centy) {
case 1:
printf(" a %d cent\n",centy);
break;
case 2 ... 4:
printf(" a %d centy\n",centy);
break;
default:
printf(" a %d centov\n",centy);
break;
}
但是,當我鍵入5.56它會說,我已經輸入控制檯5.55。你怎麼看。我應該改變什麼?我是新手所以...
http://stackoverflow.com/q/588004/3185968 – EOF
一切都是正確的,除了你的期望:) –
你期望'suma-cele'是0.56,但它可能是0.5599999999999999。 –