I have two thirds of my program working, but the last part I am having a hard time figuring out.
For the last part of the program it should output a 'plus' symbol using asterisks. The size of this is user input.
Ex:
Unfortunately I am somewhat lost as to how I can accomplish this.
This is my program so far, the bottom part with the "Plus" comment is where I am having difficulty.
Code:
#include<stdio.h>
int main()
{
int width=0;
int shape=0;
int row_counter=0;
int col_counter=0;
printf("Enter how wide the shape is to be: ");
scanf("%d", &width);
printf("Enter:\n");
printf(" 1) For a filled square,\n");
printf(" 2) For a lower triangle, or,\n");
printf(" 3) For a plus\n");
scanf("%d", &shape);
int mid= (width+1)/2;
if (shape==1) //square
{
for (row_counter=0; row_counter<width; row_counter=row_counter+1)
{
for (col_counter=0; col_counter<width; col_counter=col_counter+1)
{
printf("*");
}
printf("\n");
}
}
if (shape==2) //triangle
{
for (row_counter=1; row_counter<=width; row_counter=row_counter+1)
{
for (col_counter=1; col_counter<=row_counter; col_counter=col_counter+1)
{
printf("*");
}
printf("\n");
}
}
if (shape==3) //plus
{
for (row_counter=0; row_counter<width; row_counter=row_counter+1)
{
for (col_counter=0; col_counter<mid; col_counter=col_counter+1)
{
printf(" ");
}
for (col_counter=0; col_counter==mid; col_counter=col_counter+1)
{
printf("*");
}
}
printf("\n");
}
}
Any help or hints would be greatly appreciated! =)