Hey I am very new to programming. I am taking my first C++ class. I am a little embarrassed to ask a simple question but I am stuck.
I want to code a pattern that can vary by size etc. It looks like
*****
5****
55***
555**
5555*
or
********
9*******
99******
999*****
You get the idea. size can vary say from 5 to 100 (that doesnt matter) what matters is the *&&^%$## logic to get there.
So I definitely want to use a loop, or more accurately a nest of loops. Where the number falls changes depending on the size of the pattern but in a predictable fashion so here are some thoughts:
row 1 is size of the pattern minus (size - 1) so when row equals one I want "*" size times. For now just assume size is obtained from the user.
for (row = 1; row <= size; row++)
for (col = 1; col <= size; col++)
{
if (row == 1 && col <= size)
cout << "*";
else if (row == 2 && col == 1)
cout << size;
else
cout << "*";
)
That doesnt work.
Next thought:
for (row = 1; row <= size; row++)
for (col = 1; col <= size; col++)
{
if (row == (size - (size - row) && row != 1)
{
do
cout << "*";
while (col <= size)
}
else if (row == (size - (size - row)) && col <= (size - row))
cout << size;
else << "*";
cout << endl;
}
But this falls short of the requirement as well, I think.
Well if anyone has a push in the right direction I would appreciate it.
Thank you
Mai