In a tetris game, I am just preparing it. I made an unsigned int for the score. I want to know how I would display the amount of "score" into a message box or Dialog. Preferably Message. Thanks.
Printable View
In a tetris game, I am just preparing it. I made an unsigned int for the score. I want to know how I would display the amount of "score" into a message box or Dialog. Preferably Message. Thanks.
Perhaps you could do something like this:
unsigned int value;
char string [80];
// Create a string
sprintf (string "Value is %d\n", value);
// Print the string
AfxMessageBox (string);
Hmm... I am doing it in C++. That looks like C... I tried doing it like this:
But it didn't work..Code:MessageBox (NULL, " #1: "<<score<<"", "Scores", MB_OK);
You cannot utilize this functionality "<<" in your MessageBox. This is a stream class overload type thingy, and so you must use traditional C syntax. No worries, though. C++ IS C!
Ok, then im not good with C. How would i display the score in my Message Box then? Here is what i have so far for it:
(note: just snippets)
Code:unsigned int score = 0;
char string [80];
//and below....
case IDC_BUTTON4:
MessageBox(NULL, " #1 - \n #2 - \n #3 -", "Hi-Scores", MB_OK);
break;
You might do:
sprintf(buff, " The High Score Is %i", score);
Then MessageBox buff...
Clarification:
You don't use the sprintf() to print out the result on the screen, just converting the int into a string.
Just create one string and output it.
CString sScore;
sScore.Format("High Score: %d", m_highScore);
AfxMessageBox(sScore);
Or for those of us who detest MFC:
Code:char messageBuffer[WHATEVER_SIZE];
snprintf(messageBuffer, sizeof(messageBuffer), "High Score: %d", m_highScore);
MessageBox(hWnd, messageBuffer, "Score", MB_OK);