Problem with a simple Arithmetic equation.

This is a discussion on Problem with a simple Arithmetic equation. within the C Programming forums, part of the General Programming Boards category; Greeting EveryOne Why am i always getting 0 as a result in the following code? Code: #include <stdio.h> int CelsiusToFehrenheit(int ...

1. Problem with a simple Arithmetic equation.

Greeting EveryOne

Why am i always getting 0 as a result in the following code?

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

int CelsiusToFehrenheit(int F);

int main()
{
int i;
int j;

j = (5/9)*(40-32);

printf("\n");
printf("40F = %dC\n\n", j);
printf("100F = %dC\n\n",CelsiusToFehrenheit(100));

printf("Celsius\t\t\tFehrenheit\n");

for (i=1; i<=10; i++)
{
printf("%d\t\t\t%d\n", i, CelsiusToFehrenheit(i));
}

printf("\n");
return 0;
}

int CelsiusToFehrenheit(int F)
{
int C;
C = (5/9)*(F-32);
return C;
}```

2. What is 5 / 9 ? 0.
What's 0 * anything? 0.

If you want floating point numbers, you need floating point variables.

Quzah.

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

float CelsiusToFehrenheit(float F);

int main()
{
float i;
float j;

j = (5.0/9)*(40-32);

printf("\n");
printf("40F = %.2fC\n\n", j);
printf("100F = %.2fC\n\n",CelsiusToFehrenheit(100.0));

printf("Celsius\t\t\tFehrenheit\n");

for (i=1; i<=10; i++)
{
printf("%.0f\t\t\t%.2f\n", i, CelsiusToFehrenheit(i));
}

printf("\n");
return 0;
}

float CelsiusToFehrenheit(float F)
{
float C;
C = (5.0/9)*(F-32);
return C;
}```
any other tips?

4. Should your temperatures be reported in tenths or hundredths of a degree? I'm used to seeing them in just integers.

5. Should your temperatures be reported in tenths or hundredths of a degree? I'm used to seeing them in just integers.
The exercise was tended to practice the printf function and how it handles ints and floats.

6. I would print them in tenths.