I'm trying to make a code that can draw a square or triangle using characters. The user would specify the shape wanted, the character used, and the size.
ex: Square, #, and 8
########
########
########
########
########
########
########
########
########
or Triangle, @ and 6.
@
@@
@@@
@@@@
@@@@@
@@@@@@
@@@@@
@@@@
@@@
@@
@
Here's my code so far. I got the menu and inputs. Just gotta do the technical end of things...like drawing the shapes. lol
Here is how to add a control for the square. Use the same methodology for the triangle, but change the for(j) loop to limit the number of characters printed on each line. That's the part that gets interesting.
#include <iostream>
usingnamespace std;
int main()
{
int displayChar;
int lineLength;
char draw;
cout << "******************" << endl;
cout << "* 1 - Triangle *" << endl;
cout << "* 2 - Square *" << endl;
cout << "* *" << endl;
cout << "* 0 - EXIT *" << endl;
cout << "******************" << endl;
cout << "\n Enter Option Number: ";
cin >> draw;
cout << "\n Enter character to draw shape with: ";
cin >> displayChar;
cout << "\n Enter the line length: ";
cin >> lineLength;
// Draw square
if (draw == 2) // Use an if or a switch to determine which shape we are drawing
{
for (int i=0; i<lineLength ; i++) // each i represents a row (we will have lineLength rows)
{
cout << endl; //This adds the space at the end of the row
//you could do this at the end but you seem to do \n at the start of each statement
for (int j=0; j < lineLength ; j++) // This writes a character lineLength times.
{
cout << displayChar;
}
}
}
}