1
while(true)
{
    mysql_query(conn, " select close, id from fivemin order by id DESC LIMIT 5 ");

    result = mysql_store_result(conn);
    num_fields = mysql_num_fields(result);
    float sum = 0;
    while((row=mysql_fetch_row(result)))
        {
                 sum += atof(row[0]);
                 last_id = atoi(row[1]);

        }
    float ma;
    ma=sum/5.0;
    if(previous_last_id != last_id)
        {
        cout << "Simple moving Average: " << ma << endl;
        previous_last_id = last_id;
        }

     mysql_query(conn,"insert into sma values("+ma+")");
}

i want to store float ma in my db table but error: invalid operands of types 'const char[24]' and 'float' to binary 'operator+'

1 Answer 1

1

"insert into sma values("+ma+")" this doesn't work in C. Maybe use sprintf("insert into sma values(%f)", ma);

Also, do you really want the infinite loop? Where do you exit it?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.