Advertisement

problem with double

Started by May 24, 2000 09:02 PM
0 comments, last by gameprogrammerwiz 24 years, 6 months ago
for some reason, my drawtext function isnt wanting to display a double...or maybe it has something to do with sprintf. here is an example of my code: ============================================================ void drawtext(char* dtstr, int dtx, int dty); double mydouble = 0; if(KEY_DOWN(VK_DOWN)) { mydouble = mydouble + 0.25; } sprintf(buf, "mydouble: %d", mydouble); drawtext(buf, 0, 0); void drawtext(char* dtstr, int dtx, int dty) { HDC hdc; if (lpddsback->GetDC(&hdc) == DD_OK) { SetBkColor(hdc, RGB(0, 0, 0)); SetTextColor(hdc, RGB(255, 255, 255)); TextOut(hdc, dtx, dty, dtstr, strlen(dtstr)); lpddsback->ReleaseDC(hdc); } } =========================================================== ok, this all compiles and runs fine, but it just displays "mydouble: 0" all the time, even when you press the down arrow key. this works fine with ints, but not with double for some reason. anyone have any ideas?
==============================
whats a signature?
htm[s]l[/s]
quote: Original post by gameprogrammerwiz

sprintf(buf, "mydouble: %d", mydouble);



You need a different format specifier. %d is for integers, you need to use %f.


Andrew

This topic is closed to new replies.

Advertisement