The first print in your code (and similarly the others):
printf("enter height of box: ")
By default, this line will put the text into a buffer. The buffer is written to terminal ("flushed") only if either one of the following happens:
- The buffer gets full (can be 1024 bytes, 16384, or any other number).
There is a newline at the end of the text (assuming the output is to the terminal).
Note that this is a common behavior, but not guaranteed by the standard. Read Is stdout line buffered, unbuffered or indeterminate by default? to cover this subject.
Some C implementations will automatically flush stdout when you read from stdin, but many implementations don't.
Read Does reading from stdin flush stdout? to cover this subject.
So you can see your prompt if you change the line to:
printf("enter height of box: \n");
A second option, is to force a flush, so that the buffer is written to the output:
printf("enter height of box: ");
fflush(stdout);
A third option is to disable buffering completely. For that, you can use setbuf:
void setbuf( FILE* stream, char* buffer );
- buffer -
pointer to a buffer for the stream to use. If NULL is supplied, the buffering is turned off. If not null, must be able to hold at least BUFSIZ characters
So, simply add the following at the beginning of the program, and all stdout buffering will be turned off:
setbuf(stdout, NULL);