The exercise:
Write a function called strToFloat that converts a character string into a floating point value. Have the function accept an optional leading minus sign. So, the call
strToFloat("-867.6921")
should return the value -867.6921.
The test value is 123.123 in character format.
All is going well except something with my last subroutine with switch case statement multiplicationa is off. Got me scratching my head. Here's the output.
Code:
The number of decimal places are: 3
Decimal character string extracted to buffer: 123123
Decimal result=123123
Converted completely back to decimal: 123.123001
Here is the switch case structure. I'm not sure if its my initializing of floats I'm doing wrong or what.
Code:
void decPlaceMult(double number)
{
float answer=0;
switch(count)
{
case 1:
answer=number*.1;
break;
case 2:
answer=number*.01;
break;
case 3:
answer=number*.001;
break;
case 4:
answer=number*.0001;
break;
case 5:
answer=number*.00001;
break;
default:
break;
}
printf("Converted completely back to decimal: %f",answer);
getchar();
return;
}
Any insight greatly appreciated.