Jan 25, 2016 at 2:42pm UTC
So I have the following code that will print the shapes of a triangle and a diamond. How can I change it to make the user tell which shape they would like to have drawn and the height of the shape??
int main()
{
int i;
for( i=0;i<3;i++)
{
for(int j=3;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" +";
cout<<endl;
}
for(i=3;i>0;i--)
{
for(int j=3;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" +";
cout<<endl;
}
for(int i=0;i<6;i++)
{
for(int j=6;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" &";
cout<<endl;
}
}
Jan 25, 2016 at 2:49pm UTC
Turn the shape writing code into functions.
Get input from the user.
Call one of the functions depending on the input.
Jan 25, 2016 at 3:29pm UTC
No. You could build the whole thing in one function with if statements or switches or other such.
Start learning.