I get the get following shape to appear correctly when I input 9
[but it wont work when I enter in 6?
QUOTE
Please see attachment - the first one looks correct with 9 being the size but 6 wont work?
Here is my code - whats wrong with it?
p.s I am not yet very C++ literate so please be specific and explain in full terms.
CODE
#include <iostream>
using namespace std;
//void function with one value parameter of type int
void drawFigure (int space, int size)
{//Beginning of void function
for (space = space/2; space > 0; space --)//This corrects the spacing so its all inline
{//Beginning of for loop for spaces
cout << " ";
}//End of for loop for spaces
for (int i = 1; i <= size; i++)//This controlles the lines
{//Beginning of for loop for characers
cout << "*";//This is the character used
}//End of for loop for characters
}//End of void function
int main ( )
{
int size;
int n;
//Input
cout << "What size figue would you like to draw?";
cin >> size;
//For loop that works with the lines, relates to the top half on the tree
for (n = 0; n < size; n = n+2)
{
drawFigure (n, size -n);
cout << endl;
cout << endl;
}
//This is the part that the top half and the bottom half of the tree meet up
n = n-2;
//For loop that workes with the lines, relates to the bottom half of the tree
for ( n = n-2;n >=0; n=n-2)
{
drawFigure (n,size-n);
cout << endl;
cout << endl;
}
system ("pause");
return 0;
}
[Mod Edit] for those who don't want to download a word doc:
the output looks like:
*******
.*****
..***
...*
..***
.*****
*******
or with 6 as:
******
.****
..**
..**
.****
******
[/Edit]