I am making a project for school and i need to make a system that keeps the temperature around a set temperature (this is done by a phidget sensor and turning a heating and cooling
 element on and off.) the sensors values can be converted to degrees celcius with the formula ((Current Temperature + 50)\*4) and i got it working for a stactic 20 degrees celcius, but now i am trying to get a temprature from a database and keep it around that temprature instead(so the temprature can be changed inside the room where the heating and cooling elements are). but when i try to convert the temperature that i got from the database to the sensor value with the formula the temp variable starts giving random numbers and i dont know why. Can someone explain or help? 

(See comment toward bottom of code example for problem location)

```
//my code is a code written for controlling the temprature in a room
//this is done by a phidget sensor and turning a heating and cooling
//element on and of.

#include <phidget21.h> // voor phidgetfucties
#include <stdio.h>   // voor printf()
#include <mysql/mysql.h> // voor mysql querys
#include <my_global.h>

int main (int argc, char* argv[])
{   //variables
int val;
int gewensteTempratuur = 280;
int gewensteGradenCelcius = 0;
int i = 0;
int temp = 0;

CPhidgetInterfaceKitHandle ifKit = 0;
CPhidgetInterfaceKit_create(&ifKit);

CPhidget_open((CPhidgetHandle)ifKit,-1);

for(;;)
{
    CPhidgetInterfaceKit_getSensorValue(ifKit,0,&val);

    printf("Value %d \n", val);

    if(val < (gewensteTempratuur - 4)){
    //verwarming
    CPhidgetInterfaceKit_setOutputState(ifKit,0,1);
    //airco
    CPhidgetInterfaceKit_setOutputState(ifKit,1,0);
    }

    if(val > (gewensteTempratuur + 4)){
        //verwarming
        CPhidgetInterfaceKit_setOutputState(ifKit,0,0);
        //airco
        CPhidgetInterfaceKit_setOutputState(ifKit,1,1);

    }

    if((val < (gewensteTempratuur + 4)) && (val > (gewensteTempratuur - 4)))         {
        //verwarming
        CPhidgetInterfaceKit_setOutputState(ifKit,0,0);
        //airco
        CPhidgetInterfaceKit_setOutputState(ifKit,1,0);

    }

    //Database Connection
    MYSQL *conn;
    //Verbings gegevens

    char *server = "server";
    char *user = "user";
    char *password = "pass";
    char *database = "database";

    conn = mysql_init(NULL);
    if (!mysql_real_connect(conn, server,
        user, password, database, 0, NULL, 0)) {
        fprintf(stderr, "%s\n", mysql_error(conn));
    }

    //getting information from the database
    if (mysql_query(conn, "SELECT Gewenstetemperatuur FROM SensorValue")){
        mysql_error(conn);
        }

        MYSQL_RES *result = mysql_store_result(conn);

        if (result == NULL){
        mysql_error(conn);
        }

        int num_fields = mysql_num_fields(result);

        MYSQL_ROW row;

        while ((row = mysql_fetch_row(result))){
            for (i = 0; i < num_fields; i++){
            printf("%s ", row[i] ? row[i] : "NULL");

            gewensteGradenCelcius = (int)row[i];
            temp = gewensteGradenCelcius;

            printf("\n %s \n", gewensteGradenCelcius);
            printf("%d \n",temp )

            //Here is were is get stuck if i try to take the value and run it trough a 
            //formula like (gewensteGradenCelcius + 50) * 4 and the try to print the 
            //gewensteGradenCelcius just puts out nothing
            }
            printf("\n");
            }

            mysql_free_result(result);
            usleep(1500000);
            }

    }

```