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?

1 Answers

Ishaan Javali On Best Solutions

The reason that you are getting this error is because finalTemp is of the type int and that can only hold integers. If temp1 is either a double or int, then you can do:

double finalTemp = (temp1 - 32) * 5 / 9 + 273.15;

This code will get the temperature as a double, (which can hold decimals).

However, if finalTemp is an int, as you initially had, it will not be possible to get it to

recognize 273.15 as a decimal.