# help needed in floating point

• 06-27-2005
akshayabc
help needed in floating point

Q1
Output of the following code- C.
Code:

```main() {   float a=0.7;   if(a<0.7)   printf("C");   else   printf("C++); }```
But if we change the if condition from a<0.7 to a<0.7f we get output- C++.

Q2
The following code gives runtime error- Floating point formats not linked. When does this error occur in a program.
Code:

```main() {   struct emp   {   char name[20];   float sal;   };   struct emp e[10];   int i;   for(i=0;i<=9;i++)   scanf("%s %f",e[i]name,&e[i].sal); }```
• 06-27-2005
willc0de4food
for your first question, i believe when you make it: a < 0.7f for the conditional, its taking the ascii value of f and combining it with 0.7. possibly, but you really have no reason to add the 'f' after 0.7
• 06-27-2005
akshayabc
No it is not like that if u write 0.7 then it will be taken as double and if u write 0.7f then it will be taken as a float value.
• 06-27-2005
Dave_Sinkula
Quote:

Originally Posted by akshayabc
Q2
The following code gives runtime error- Floating point formats not linked. When does this error occur in a program.
Code:

```main() {   struct emp   {   char name[20];   float sal;   };   struct emp e[10];   int i;   for(i=0;i<=9;i++)   scanf("%s %f",e[i]name,&e[i].sal); }```

http://cboard.cprogramming.com/showt...171#post322171
• 06-27-2005
mitakeet
Floats/doubles are NOT capable of precisely representing many decimal values, hence your comparisons can fail. You need to test for a range.
• 06-27-2005
Salem
> But if we change the if condition from a<0.7 to a<0.7f we get output- C++.
http://cboard.cprogramming.com/showt...light=goldberg

> The following code gives runtime error- Floating point formats not linked
This may mean you're using some old DOS compiler which in an effort to minimise the amount of space a program used (when people still cared about such things), makes a rather too optimistic assumption about the need for floating point support.
Modern compilers do not suffer from this problem.