trying to draw a circle with a number in it

For an assignment that I had to do a few months ago, they provided a circle with a number drawn in it for us to use. Now I'm trying to reuse that code for a personal project, but it's not working right. I guess this was only meant for numbers 1-10, but I'm trying to get it to do bigger numbers. Instead of putting the number, it's giving me different letters. How can I get it to do any number? here is the bit of code that does the number.

 
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (char)(number + '0'));
I'm guessing it'll only work for a single digit. Is there something else that I can use to get it to do 2-3 digit numbers?
Maybe something like:

1
2
3
char text[100];
sprintf(text, "%d", number);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, text);

if I try that, it says
sprintf was not declared in this scope
and
glutBitmapString was not declared in this scope

is there another library or something I need to include to use those?
Remember to google functions to find out the purpose, interface and required header/library.
In this case it's <cstdio>

If you just need a two-character number (with leading 0) you could do this:

1
2
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (char)(number / 10 + '0'));
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (char)(number % 10 + '0'));

that worked great for two digit numbers, but I really need to be able to do three digit numbers as well
The second digit would be (number / 10) % 10
123 / 10 == 12, 12 % 10 == 2.

But the sprintf method should work too, and it's more general.
Last edited on
Thanks guys, got it figured out! :)
Topic archived. No new replies allowed.