Inspiration
I want to learn C++
What it does
Prints a shape
How I built it
with C++
Challenges I ran into
I just started C++ this week
Accomplishments that I'm proud of
It works
What I learned
variables, for loops, if statements
What's next for select a shape
Add more shapes to select
include
using namespace std;
char decide(); void makePyramid(char p); void makeSquare(char s);
int main() { char shape;
shape = decide();
makePyramid(shape);
makeSquare(shape);
return 0;
}
char decide() { char shape; cout << "Please select a shape to print" << endl; cout << "Press p for pyramid or s for square. " << endl; cin >> shape; return shape; }
void makePyramid(char shapeSelect) {
if (shapeSelect == 'p')
{
int space, rows;
cout <<"Enter number of rows: ";
cin >> rows;
for(int i = 1, k = 0; i <= rows; ++i, k = 0)
{
for(space = 1; space <= rows-i; ++space)
{
cout <<" ";
}
while(k != 2*i-1)
{
cout << "* ";
++k;
}
cout << endl;
}
}
}
void makeSquare(char shapeSelect) { if(shapeSelect == 's') { int space, rows; cout << "Enter number of rows: " << endl; cin >> rows;
for(int i = 0; i < rows; i++) //up and down
{
for(int j = 0; j < rows; j++) // right and left
{
cout << "#";
}
cout << endl;
}
}
}
Log in or sign up for Devpost to join the conversation.