I want to make a program that converts Fahrenheit to Kelvins but in the conversion, you need to add 273.15. My current code for the conversion is
int finalTemp = (temp1 - 32) * 5 / 9 + 273.15;
but it gives:
Error CS0266 Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
How do I make it recognize 273.15 as a decimal?
The reason that you are getting this error is because
finalTemp
is of the typeint
and that can only hold integers. Iftemp1
is either adouble
orint
, then you can do:This code will get the temperature as a
double
, (which can hold decimals).However, if
finalTemp
is anint
, as you initially had, it will not be possible to get it to