Reading Multiple ADC channels with a PIC18F24K22
This is another way to implement your ADC to temperature function:
/*
 * File:   AppLoop.c
 * Author: dan1138
 * Target: PIC18F24K22
 * Compiler: XC8 v2.31
 * IDE: MPLABX v5.45
 *
 * Created on March 7, 2021, 11:37 AM
 * 
 *                        PIC18F24K22
 *                 +---------:_:---------+
 *      VPP RE3 -&gt; :  1 VPP       PGD 28 : &lt;&gt; RB7 PGD
 *          RA0 &lt;&gt; :  2           PGC 27 : &lt;&gt; RB6 PGC
 *          RA1 &lt;&gt; :  3               26 : &lt;&gt; RB5
 *          RA2 &lt;&gt; :  4               25 : &lt;&gt; RB4
 *          RA3 &lt;&gt; :  5               24 : &lt;&gt; RB3
 *          RA4 &lt;&gt; :  6               23 : &lt;&gt; RB2
 *      POT RA5 &lt;&gt; :  7 AN4           22 : &lt;&gt; RB1
 *      GND VSS -&gt; :  8          INT0 21 : &lt;&gt; RB0
 *          RA7 &lt;&gt; :  9 OSC1          20 : &lt;- VDD 5v0
 *          RA6 &lt;&gt; : 10 OSC2          19 : &lt;- VSS GND
 *          RC0 &lt;&gt; : 11 SOSCO     RX1 18 : &lt;&gt; RC7 RXD
 *          RC1 &lt;&gt; : 12 SOSCI     TX1 17 : &lt;&gt; RC6 TXD
 *          RC2 &lt;&gt; : 13               16 : &lt;&gt; RC5
 *          RC3 &lt;&gt; : 14          AN16 15 : &lt;&gt; RC4 TEMP
 *                 +---------------------+
 *                         DIP-28
 * 
 * Used the MPLABX Code Configurator(MCC) to generate the code to support the ADC and UART
 * 
 * POT:  10K ohm, Range: VSS to VDD
 * TEMP: TMP36, https://www.analog.com/media/en/technical-documentation/data-sheets/TMP35_36_37.pdf
 */

#include &quot;mcc_generated_files/mcc.h&quot;
/*
 * Function: Read_TMP36
 * 
 * Input: None
 * 
 * Output: float Temperature in °C (-40 to +125)
 * 
 * Notes: The Analog Device TMP36 has a 0.5 volt offset
 *        so it can indicate temperatures below 0C without
 *        making the output voltage negative to the VSS
 *        ground reference.
 */
#define ADC_VREF  (5000)    /* ADC voltage reference in millivolts */
#define TMP_OFFSET (500)    /* TMP36 voltage offset in millivolts  */
#define TMP_SLOPE   (10)    /* TMP36 slope in millivolts per °C    */
float Read_TMP36(void)
{
    float result = 0.0;
    uint32_t ADC_result;
    
    ADC_SelectChannel(TEMP);
    ADC_StartConversion();
    for(;;)
    {
        if(ADC_IsConversionDone()) break;
    }
    ADC_result  = ADC_GetConversionResult();
    ADC_result  = (ADC_result * ADC_VREF) &gt;&gt; 16;
    result  = (float)(ADC_result &amp; 0xFFFF);
    result -= TMP_OFFSET;
    result *= 1.0/TMP_SLOPE;
    
    return result;
}
/*
 * Function: Read_Pot
 * 
 * Input: None
 * 
 * Output: uint8_t
 * 
 * Description:
 *  Returns an 8-bit value from 0 to 255 that represents
 *  the voltage of an analog input between VSS and VDD.
 */
uint8_t Read_Pot(void)
{
    uint8_t result = 0.0;
    
    ADC_SelectChannel(POT);
    ADC_StartConversion();
    for(;;)
    {
        if(ADC_IsConversionDone()) break;
    }
    result = (uint8_t)(ADC_GetConversionResult()&gt;&gt;8);

    return result;
}

void AppLoop(void) 
{
    float Temprature, Temprature_output;
    uint8_t SetPoint, SetPoint_output;
    
    printf(&quot;\r\nPIC18F24K22 ADC PWM temp start built on %s at %s\r\n&quot;, __DATE__, __TIME__);
    
    Temprature = Read_TMP36();
    Temprature_output = Temprature;
    printf(&quot;Temp: %f\r\n&quot;, Temprature_output);

    SetPoint = Read_Pot();
    SetPoint_output = SetPoint;
    printf(&quot;Set point: %u\r\n&quot;, SetPoint_output);
    
    for(;;)
    {
        Temprature = Read_TMP36();
        if(Temprature_output != Temprature)
        {
            Temprature_output = Temprature;
            printf(&quot;Temp: %f\r\n&quot;, Temprature_output);
        }
        
        SetPoint = Read_Pot();
        if(SetPoint_output != SetPoint)
        {
            SetPoint_output = SetPoint;
            printf(&quot;Set point: %u\r\n&quot;, SetPoint_output);
        }
    }
}

You will need to use the MCC to generate the rest of the code but this is what I created to test the calculations in the MPLABX simulator.
Note that I setup the ADC to use the &quot;left justified&quot; mode when reading the POT and TEMP analog voltages.