Using dev c++ I am building a class the generates 3 bundles of fruit or vegetables. I am stuck on the issue of producing more that one output fruit or veggie from the randomly selected array. I only produce one element from the array.
In your output() member function you state that a Box will contain 3 items (your for loop runs three times), so you should probably declare your array as such. It would be advisable to use a const variable:
constint BOX_SIZE = 3;
Which you can then use as: string Box[BOX_SIZE]; //line 16 That makes a lot more sense to someone reading your code.
Now, let's look at your output member function:
1 2 3 4 5 6 7 8 9 10 11 12 13
void BoxOfProduce::output()
{
int i;
cout<<"your bundle: ";
for( i=0; i < 3; i++) //this is your loop, which will run three times
{
Box[i] = full_list[i];
}
srand(time(0)); //this is the code which selects a random product and prints it
int boxee = rand()% 5;
displayWord( boxee);
}
Why is the code which selects a random product and prints it outside of the for-loop? This will cause it to run only once, after the loop has already run. You are meaning to fill the Box with random products, so what you actually want to do is:
1 2 3 4 5 6 7
for( i=0; i < 3; i++) //this is your loop, which will run three times
{
srand(time(0)); //you only need to do this once, so this could be outside of the loop
int boxee = rand()% 5; //make random number
Box[i] = full_list[boxee]; //add it to the Box
displayWord( boxee); //display it
}