0

I was wondering is it possible to put this into an array so that it would print the same thing three times?

ChineseFireball dragon = ChineseFireball("Scarlet", "Beast", "China", 6, 25);

dragon.print();

2 Answers 2

1
/* Populate */
ChineseFireball dragons[3];
for (int i = 0; i < 3; i++)
{
    dragons[i] = ChineseFireball("Scarlet", "Beast", "China", 6, 25);
}

/* Print */
for (int i = 0; i < 3; i++)
{
    dragons[i].print();
}

if array is not necessary:

ChineseFireball dragon = ChineseFireball("Scarlet", "Beast", "China", 6, 25);
for (int i = 0; i < 3; i++)
{
    dragon.print();
}
Sign up to request clarification or add additional context in comments.

Comments

0

Sure, here is how:

ChineseFireball dragons[3];
for (int i = 0; i < 3; i++)
{
    dragons[i] = ChineseFireball("Scarlet", "Beast", "China", 6, 25);
}

And then to print, simply loop through the dragons array and call print() on each element.

That's assuming you want to have three dragons. If you simply want to execute print() on the single dragon instance three times, run it in a loop like the one above.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.