Hi,
I'm a beginner of C++ programming. I am trying to write a void funtion for the following question but in vain. Please help me.
Here's the question:
Suppose we want to display the following figure containing the alphabetic character V on yhe screen:
#^^^^^^^^^#
^#^^^^^^^#^
^^#^^^^^#^^
^^^#^^^#^^^
^^^^#^#^^^^
^^^^^#^^^^^
We want to be able to change the number of rows. In the figure above the number of rows is 6. If the number of rows is 4. the figure will look as follows:
#^^^^^#
^#^^^#^
^^#^#^^
^^^#^^^
Write a void function drawShape that displays such a figure on the screen. There should be one parameter (of type int), namely the number of rows as indicated above.
The hint i have here is:
Use for loops. Suppose nrP contains the number of rows. Then the ith row should consist of (i - 1)^ characters, followed by one #character, followed by (2 * nrP - 2 * i - 1)^ characters, followed by another # character, followed by another (i - 1)^ characters. The last row however, should contain only one # character.
Here's what i have written till now:
void drawShape (int nrP)
{
for (int i = 1); i <= n; i++)
cout << '#' << '^' << endl;
}
But the above does not work of course.