Oh man, you are so close!
Here it is: Changes are in red.
#include <stdio.h>
int main( void )
{
int row;
int col;
int num;
printf("\n");
printf( "Please Enter a Number Between 1 and 20: " );
scanf( "%d", &num );
printf( "\n" );
//________________________ Square
row = 0;
while(row < num)
{
col = 0;
while( col < num)
{
printf("*");
col++;
}
printf("\n");
row++;
}
printf("\n");
//________________________ Hollow Square
col = 0;
while(col < num)
{
printf("*");
col++;
}
printf("\n");
row = 1;
while(row < (num - 1))
{
printf("*");
row++;
col = 2;
while(col <= num)
{
if (col == num)
printf("*");
else
printf(" ");
col++;
}
printf("\n");
}
if ( row < num )
{
col = 0;
while(col < num)
{
printf("*");
col++;
}
}
printf("\n");
return 0;
}
Now lets make sure you understand this.
First issue was:
...
row = 0;
while(row < (num - 2))
...
The issue here is that you already wrote the first row in the while loop preceding this one. So setting row to zero doesn't make any sense considering you are wanting to draw with this loop starting at the second (2-1) row. Also you want to draw these hollow lines up to the last row which is num-1 not num-2. Hence:
...
row = 1;
while(row < (num - 1))
...
Next was the move of
col++;
into the inner while loop. If you actually ran your code you should have noticed the infinite loop... ^^;;
And lastly the:
if ( row < num )
{
...
}
In the case of 1 you draw the top and the bottom regardless of row size, this corrects that behavior.
As a bonus side note: Developer tip: if your code doesn't do what you expect it to do, step through it
by hand. i.e. write down every step the code makes
on paper. From inputs, to iterations, to outputs, and you are bound to find the tiny error that you made.
Regards.