# there's something wrong.. :/

Discussion in 'C' started by jam143, Jul 2, 2011.

1. ### jam143New Member

Joined:
Jul 1, 2011
Messages:
8
0
Trophy Points:
0
Occupation:
n/a
Location:
philippines
Hello, I think there's something wrong in my code.
I made a program converting Â°C-Â°F .
the formula is Â°F = (1.8*Â°C) + 32

Here's the code:

Code:
```#include <stdio.h>
#include <conio.h>

int main()
{
int C;
int F;
printf("Enter the value of Â°C: ");

scanf("%d", &C);

total = (1.8 * C) + 32;

printf("Â°F=%d", F);

getch();

}
```
when I enter the value of C as 2. the answer should be 35.6 .. but it only shows 35.. it doesn't have any decimals.. what should I do?? thank you in advance if someone will help..

2. ### jam143New Member

Joined:
Jul 1, 2011
Messages:
8
0
Trophy Points:
0
Occupation:
n/a
Location:
philippines
ahh no.. it's wrong.. here's the correct one..

Code:
```#include <stdio.h>
#include <conio.h>

int main()
{
int C;
int F;
printf("Enter the value of Â°C: ");

scanf("%d", &C);

F = (1.8 * C) + 32;

printf("Â°F=%d", F);

getch();

}
```

3. ### lionaneeshActive Member

Joined:
Mar 21, 2010
Messages:
848
224
Trophy Points:
43
Occupation:
Student
Location:
India
TO get the output in decimals we need to use the 'float' data-type .

Corrected Code :-

Code:
```#include <stdio.h>
#include <conio.h>

int main()
{
int C;
[COLOR="Red"]float F;[/COLOR]
printf("Enter the value of Â°C: ");

scanf("%d", &C);

F = (1.8 * C) + 32;

[COLOR="Red"]printf("Â°F=%f", F);[/COLOR]

getch();

}

```
Output :-

Code:
```Enter the value of C: 2
F=35.599998
```

4. ### gpk kishoreNew Member

Joined:
Jun 30, 2011
Messages:
82
0
Trophy Points:
0
what u(jam 143) have writen is absolutely correct but...............
there is only one controversy that your answer will not be printed in decimals
because int range is-32768to 32767 so it cannot accept decimal values
so we use other data type called "float" whose range is -3.4e-38 to -3.4e+38
so we can use it

just print the answer as printf("F=%f",f);
you will get the required answer

5. ### jam143New Member

Joined:
Jul 1, 2011
Messages:
8
0
Trophy Points:
0
Occupation:
n/a
Location:
philippines
thank you for help.. for the both of you.. really big help.. thank you so much.. )

6. ### kupparamakrishnaNew Member

Joined:
Jun 23, 2011
Messages:
16
0
Trophy Points:
0
Occupation:
student
Location:
banglore
Iam sorry if am wrong about the above program how can int f;
give you floating point value if u write %f.

7. ### gpk kishoreNew Member

Joined:
Jun 30, 2011
Messages:
82
0
Trophy Points:
0
yes sir,
it will show abnormal termination
what i mean in before post is to cast the data type
for example x=(float)y;

Joined:
Jun 23, 2011
Messages:
16