int c;
int f = 20;
c = 5 / 9 * (f - 32);
Console.WriteLine(c);
Console.ReadLine();
If I run this code c ends up being 0, which is wrong. Can anyone tell me why?
Because your calculation is being done in integer type. I believe c is double type variable.
c = 5d / 9 * (f - 32.0);
use 32.0 or 32d so that one of the operands is double, also do the same for 5/9.
Also you need to define c as double.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With