#include <iostream>
#include <vector>
usingnamespace std;
int main()
{
int x=1;
int maxWidth=5;
vector<int> printChars (maxWidth);
for (int i=0;i<maxWidth;i++)//fills vectors with characters to be printed
{
printChars[i]=i+1;
}
while (x!=0)
{
if(x>maxWidth)//this will not return true until maxWidth has been achieved
{
while(x!=0)//this while loop will print back down until width=0
{
for(int i=0;i<x-1;i++)
{
cout<<printChars[i];
}
cout<<"\n";
x--;
}
}
else//just counts up to print first half
{
for (int i=0;i<x-1;i++)
{
cout<<printChars[i];
}
cout<<"\n";
x++;
}
}
return 0;
}
After I wrote it I realized naming x as currentWidth might have made it a little easier to understand.