How to make strings equal a certain number

I need this understanding because I am doing a slot machine exercise, and for whatever random number between 0 and 3. How would I code it so that if a certain number was given, the outcome would be a string. for example, if I wanted an image called "image0.jpg" to be outputted, how would i code it so that whenever 1 is inputted, I get the picture outputted, or when "image1.jpg" is outputted whenever I hit number 1. here are the given instructions, followed by my code:
----------------------------------------------------------------------------
Function Requirements:
Signature of function (header)

Return value: Image - the Image object generated based on location and reel value passed in.

Parameters: (all by value)

Point - the lower left corner of image location for this reel
int - which reel image it is

Body of function

This function will construct and return a single Image object at the location passed in. The value passed in determines which image file it should use. You should have a minimum of 4 different reel images. I have provided 4 fruit images you can use, but you may use your own images instead.

You must use the following names for your images:

image0.jpg
image1.jpg
image2.jpg
image3.jpg
-------------------------------------------------------
Image out_image(Point pt, int picture)
{
if (picture == 0)
{
return "image0.jpg";
}
if (picture == 1)
{
return "image1.jpg";
}
if (picture == 2)
{
return "image2.jpg";
}
if (picture == 3)
{
return "image3.jpg";
}
}
Well, I am guessing you are trying to output to the screen which for that you need to use some sort of handle to a device content (HDC). Before we get into that though, your if statements are fine but it would be better to use a switch statement. For a slots game, I would import all the images into an HBITMAP when the game first loads or have them setup as resources. Resources would be best because you are not using that many images in the slots and some will repeat, and you can read them much faster. this will make your program size larger, but there are not many images so it would be worth it so that it runs much faster.

If you have them set up as resources, you will be giving them resource names like IDB_IMAGE1. Then you can Bitblt right to the screen the image you choose from the resource once you place it in a HBITMAP using the LoadBitmap function. If you need help with these functions, post again and I will explain what I can but they are fairly easy to understand and there are great books which can explain them better then I can in a post.

Since the images are being posted to the screen by the program, you don't want to try and read the image itself to determine what image it is but rather have the math do determine which image it displays tell you which image it is. It would be much easier this way.

For example, you could have a deque of numbers. Maybe 20 numbers in there and you push back the number in the 0 position and then pop the front out every so many milliseconds. The speeds you would have to play with to get right and have the images update every so many frames to show that they are moving to the next one.

This is just how I would write this code thinking about it for only 2 minutes, not sure how you are going about it in regards to displaying it to the screen but whatever you use for that, I would use that.
Topic archived. No new replies allowed.