だから私は、5つの数字とコンマを文字として読み取り、それらをすべて一緒に表すこのプログラムを手に入れました。私はそうすることができましたが、出力は非常に奇妙です..
コードは次のとおりです。
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i=0;
float number = 0.0;
char f;
printf("Introduce a number in the following format (ccc,cc):\n");
for(i=1; i<=6; i++){
f=getchar();
if(f=='\n' && i<6){
printf("the number is not correct.\n");
exit(1); }
if(i==4 && f!=','){
printf("The number doesn't have a comma.\n");
exit(1); }
if(i==4)
continue;
if((f<'0') || (f>'9')){
printf(" %d is not a number .\n", i);
exit(1); }
switch (i)
{
case 1 : number = (f*100);
break;
case 2 : number += (f*10);
break;
case 3 : number = number + f;
break;
case 4: ;
break;
case 5 : number += (f * 0.1);
break;
case 6 : number += (f*0.01);
break;
}
}
printf("The number you inserted is :%f\n",number);
}
数値 123,45 の出力はまったく同じ数値であるはずですが、その代わりに非常に厄介なものが得られます。
Introduce a number in the following format (ccc,cc):
123,45
The number you inserted is :5456.729980
みんな助けて?