- #1
meldave00
- 39
- 0
Hi,
Please see my code below. If I enter 4.42 in for my first float
and 10.00 in for my second float and I muliply them together I get
a result of 44.200001. The reason is because the compiler thinks
that 4.42 = 4.4200001 (I checked this during debug). Why does this
do this? How does anybody get accurate results when working with
C? Anyone know what the work around is for this type of issue?
I'm refreshing my knowledge of C... I'm a little rusty.
#include <stdio.h>
void main(){
float aFloat1; float aFloat2; float aFloat3;
printf(" Please enter the value of float #1: ");
scanf("%f",&aFloat1);
printf(" Please enter the value of float #2: ");
scanf("%f", &aFloat2);
aFloat3 = aFloat2 * aFloat1;
printf("\n");
printf(" The value of aFloat3 is: $%f \n\n", aFloat3);
getchar();
getchar();
};
regards,
meldave00
Please see my code below. If I enter 4.42 in for my first float
and 10.00 in for my second float and I muliply them together I get
a result of 44.200001. The reason is because the compiler thinks
that 4.42 = 4.4200001 (I checked this during debug). Why does this
do this? How does anybody get accurate results when working with
C? Anyone know what the work around is for this type of issue?
I'm refreshing my knowledge of C... I'm a little rusty.
#include <stdio.h>
void main(){
float aFloat1; float aFloat2; float aFloat3;
printf(" Please enter the value of float #1: ");
scanf("%f",&aFloat1);
printf(" Please enter the value of float #2: ");
scanf("%f", &aFloat2);
aFloat3 = aFloat2 * aFloat1;
printf("\n");
printf(" The value of aFloat3 is: $%f \n\n", aFloat3);
getchar();
getchar();
};
regards,
meldave00