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";
}
}
Errors are on each line where return occurs;
error: conversion from ?const char*? to non-scalar type ?Image? requested
You are not returning the proper thing. It says you should return "a single Image object" at the given point. The picture is indexed by number, so the file you should open is "image0.jpg", "image1.jpg", etc.
char fileName[] = "Image*.jpg";
for (int nIndex = 1; nIndex < 4; nIndex++)
{
fileName[5] = '0' + nIndex;
// so you see the change...
cout << fileName << endl;
// do your fstream work.
} // end the for loop.
I don't know if you have learned c-style string or a character array like I present but it is the other way around the string class