*Updated after reading comment*
double TF_, TK_, TR_;
printf("What is the temperature in Farenheit? \n");
scanf("%Lf", &TF_);
TF_ = TR_ - 459.67;
TR_ = (9 / 5)*TK_;
printf("The Kelvin equivalent to the given temperature in Farenheit is %Lf \n", TK_);
In your code, you are reading in the temperature in Fahrenheit then
overwriting that with
TR_ - 459.67
. Why even input TF in the first place? Also, these equations are still incorrect for what your printf statements say is happening. Fahrenheit to Rankine is
R = F + 459.67
and Rankine to Kelvin is
K = R * (5/9)
. Your equations are attempting to convert from Rankine to Fahrenheit, then from Kelvin to Rankine. This is the fixed code:
double TF_, TK_, TR_;
printf("What is the temperature in Farenheit? \n");
scanf("%Lf", &TF_);
TR_ = TF_ + 459.67;
TK_ = (5/9) * TR_;
printf("The Kelvin equivalent to the given temperature in Farenheit is %Lf \n", TK_);
I'd also recommend using useful variable names.
double fahrenheit, kelvin, rankine;
printf("What is the temperature in Farenheit? \n");
scanf("%Lf", &fahrenheit);
rankine = fahrenheit + 459.67;
kelvin = (5/9) * rankine;
printf("The Kelvin equivalent to the given temperature in Farenheit is %Lf \n", kelvin);
Quick note:
double variableName;
is a variable declaration. Now you have memory associated with a variable. That memory can hold anything right now. It could be 0; it could be random junk. You need to assign (initialize) it before using it. Example:
variableName = 0;
or more compactly
double variableName = 0;
.
The reason it often works anyways is because many operating system kernels as a security feature do not give out uninitialized memory. Also many language specifications have defaults (though whether the compiler respects this can vary). All of this can change and is out of your control. You shouldn't rely on it especially when avoiding semi-non-deterministic effects is so easy in this case. Just a simple
= 0;
.