What is wrong with my MakeBox program?

This is a discussion on What is wrong with my MakeBox program? within the C++ Programming forums, part of the General Programming Boards category; /// A program that gives the user the option to draw a box /// DrawBox version 1.0 /// by the ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    156

    What is wrong with my MakeBox program?

    /// A program that gives the user the option to draw a box
    /// DrawBox version 1.0
    /// by the legendary Golden Bunny

    #include <iostream>
    #include <conio.h>
    #include <conio.c>
    #include <string>
    #include <windows.h>

    void DrawBox(float height, float width);
    void DrawHeight(float height);
    void DrawWidth(float width);

    void main()
    {
    string name="";
    float height, width;
    cout << "Input the name of your box: ";
    cin >> name;
    cout << "Input the Height of the Box: ";
    cin >> height;
    cout << "Input the width of the Box: ";
    cin >> width;
    cout << "\nDrawing Box";
    for (int i=0;i<=16;i++) {
    Sleep(200);
    cout << "."; }
    clrscr();
    DrawBox(height, width);
    getch();
    }

    void DrawBox(float height, float width)
    {
    HANDLE output=GetStdHandle(STD_OUTPUT_HANDLE);
    COORD cursor;

    SetConsoleCursorPosition(output, cursor);

    DrawHeight(height);
    DrawWidth(width);
    cursor.Y+=height;
    DrawWidth(width);
    getch();
    }

    void DrawWidth(float width)
    {
    HANDLE output=GetStdHandle(STD_OUTPUT_HANDLE);
    COORD cursor;
    SetConsoleCursorPosition(output, cursor);

    for (int loop=0;loop<=width;loop++) {
    cursor.Y=2; cursor.X=5; cout << "-"; cursor.X++; }
    getch();
    }

    void DrawHeight(float height)
    {
    HANDLE output=GetStdHandle(STD_OUTPUT_HANDLE);
    COORD cursor;
    SetConsoleCursorPosition(output, cursor);

    for (int loop2=0;loop2<=height;loop2++) {
    cursor.Y=3; cursor.X=4; cout << "|"; cursor.Y++; }
    getch();
    }
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: goldenbunny84@hotmail.com

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  2. #2
    Aran
    Guest
    i'm recoding it now to work correctly, but just a few things to mess around with:

    1. it's impossible to output a box with float width and height if you are using ascii chars, since you can't have half a char printed to the screen.

    2. your loop is probably where the problem lies.

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    I don't know.
    Code tags.
    Errors? Unexpected output?

  4. #4
    Aran
    Guest
    here is a working function in a program that demonstrates that it works.. now you'll have to mess around with it to get it to be just golden (i'm so funny) and how you like it. (you'll have to tweak some of it to how you like)

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <conio.h>
    #include <conio.c>
    
    void printBox(int width, int height);
    COORD xyToCoord(int x, int y);
    
    int main()
    {
    
     int height, width;
    
     cout << "input height" << endl;
     cin >> height;
     cout << "input width" << endl;
     cin >> width;
     clrscr();
    
     printBox(width, height);
    
     system("PAUSE");
     return 0;
    }
    
    COORD xyToCoord(int x, int y)
    {
     COORD outputCoord = {x, y};
     return outputCoord;
    }
    
    void printBox(int width, int height)
    {
     HANDLE hOutput;
     hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    
     if (height == width)
     {
      for (int y = 0; y < height; y++)
      {
       for (int x = 0; x < width; x++)
       {
        if (y == 0 || y == (width - 1) || x == 0 || x == (height - 1))
        {
         SetConsoleCursorPosition(hOutput, xyToCoord(x, y));
         cout << "|";
        }
        else
        { cout << ".";}
        /*else if (x == 0 || x == (height))
        {
         SetConsoleCursorPosition(hOutput, xyToCoord(x, y));
         cout << "|";
        } */
       }
      }
     }
     else if (width > height)
     {
      for (int y = 0; y < width; y++)
      {
       for (int x = 0; x < width; x++)
       {
        if (y == 0 || y == (width -1))
        {
         SetConsoleCursorPosition(hOutput, xyToCoord(x, y));
         cout << "|";
        }
        else if (x == 0 || x == (height))
        {
         SetConsoleCursorPosition(hOutput, xyToCoord(x, y));
         cout << "|";
        }
       }
      }
     }
     else if (height > width)
     {
      for (int y = 0; y < height; y++)
      {
       for (int x = 0; x < height; x++)
       {
        if (y == 0 || y == (width))
        {
         SetConsoleCursorPosition(hOutput, xyToCoord(x, y));
         cout << "|";
        }
        else if (x == 0 || x == (height - 1))
        {
         SetConsoleCursorPosition(hOutput, xyToCoord(x, y));
         cout << "|";
        }
       }
      }
     }
    }
    (this works on my comp, i don't know if it will work on yours)

  5. #5
    Aran
    Guest
    if you use it, give me credit (i'm so rotten).

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    156
    well, yours actually work.....but doesn't work properly.....
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: goldenbunny84@hotmail.com

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 01-13-2007, 02:14 AM
  2. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  3. Whats wrong with this program - Output of a series
    By duffmckagan in forum C Programming
    Replies: 2
    Last Post: 07-26-2006, 10:57 AM
  4. Whats wrong with my program?
    By Ruflano in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2002, 05:09 PM
  5. what's wrong with my newbie program??
    By insoolated in forum C++ Programming
    Replies: 1
    Last Post: 09-14-2001, 09:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21