Thread: Box program almost completed need additional help

  1. #1
    Registered User
    Join Date
    Oct 2011

    Box program almost completed need additional help

    Hello everyone, I am almost finished writing a box program based on the users input of the size of the box.

    So far my program is
    #include <stdio.h>
    int num;
    int top;
    int newtop;
    int oside;
    int obot;
    int bot;
    int side;
            printf("Enter the size of a box: "); /*takes input from user*/
            scanf("%d", &num);
    top = 0;
    side = 0;
    bot = 0;
    newtop = 0;
    oside = 0;
    obot = 0;
    while (newtop != num) {
    newtop++ ;
    while (side != num) {
    side++ ;
    while(bot != num) {
    bot++ ;
    return 0;
    A sample run of the program :
    linux3[3]% ./a.out
    Enter the size of a box: 5
    However to complete the project how would I go about printing a box like this

    Any help would be appreciated ! Thank you in advance
    Last edited by Rukris; 10-31-2011 at 08:20 PM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    It's best to print both sides of the box, at the same time, so change this:
    while (side != num) {
       side++ ;
    sides2print = heightoftheBox-2;
    //to something like this:
    while(side!= sides2print) {
       if(side==0 || side equals num) 
          print *
           print space ' ' char
        if(side equals widthOfTheBox) {
           print newline
    If the user enter 3 x 3 box, the side loop will print one "row" only, since the other two rows are either the top or the bottom. So it's total height of the box, -2 equals side rows to print.

    You increment the side variable, only when it has printed the * on the far right hand side of the box, and it has printed the newline.

    Get that going and I'll help you with the diagonals. The above may be off a bit, but you'll get the idea.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. additional arguments
    By l2u in forum C Programming
    Replies: 4
    Last Post: 06-08-2006, 08:24 AM
  2. Replies: 5
    Last Post: 03-21-2004, 03:18 PM
  3. completed a program; desire input
    By spirited in forum C++ Programming
    Replies: 2
    Last Post: 05-25-2003, 08:50 AM
  4. Replies: 5
    Last Post: 08-22-2002, 03:32 PM
  5. Space Combat (50% Completed Program)
    By moonwalker in forum Game Programming
    Replies: 2
    Last Post: 07-26-2002, 08:59 AM