Hello,
I am trying to make a program that prints out a square with width defined by the user. The program compiles, and asks user for width, but after that nothing happens. What am I doing wrong?
Code:
#include<stdio.h>
/*Prompts user to enter width*/
int getwidth(int width);
/*Prints out a square*/
char printsquare (void);
int
main(void)
{
int width;
char printsquare;
width = getwidth(width);
printsquare;
return(0);
}
/*Function that prompts user to enter width */
int getwidth (int width)
{
printf("Enter width for the house, it must be odd number bigger than 5> ");
scanf("%d", &width);
return width;
}
/*Function that prints out a square */
char printsquare(void)
{
/* prints out top of the square */
int width;
int count = 0;
while(count < width)
{
printf("%c", '*');
count=count+1;
}
printf("\n");
/* prints out left and right walls of the square*/
int count1 = 0;
while(count1 < width-2)
{
printf("%c", '*');
int count2 = 0;
while(count2 < width-2) {
printf("%c", ' ');
count2=count2+1;
}
printf("%c", '*');
printf("\n");
count1=count1+1;
}
/*prints out bottom of the square*/
int count3 = 0;
while(count3 < width)
{
printf("%c", '*');
count3=count3+1;
}
printf("\n");
}
I can't get what's wrong with this code. Do you see what's wrong with it?