rectangle

This is a discussion on rectangle within the Game Programming forums, part of the General Programming Boards category; I need to print a rectangle for a game. The user enters 2 values, say 3 and 5 out put: ...

  1. #1
    Unregistered
    Guest

    Question rectangle

    I need to print a rectangle for a game.

    The user enters 2 values, say 3 and 5

    out put:

    *****
    * *
    *****

    Can this be done without anything complicated (i.e without pointers and arrays etc..)

    any suggestions?

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    graphic or just text?

  3. #3
    Unregistered
    Guest
    Just text

    its just supposed to be a hollow square made up of #.

    Does anyone know the algorithm?

    thanks

  4. #4
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    heres some code

    Code:
    cin>>x>>y; //x=3,y=5
    
    for(col=1;col<=y;col++)
    {
     gotoxy(col,1);
     cout<<"#";
     gotoxy(col,x);
     cout<<"#";
    }
    
    for(row=2;row<x;row++)
    {
     gotoxy(1,row);
     cout<<"#";
     gotoxy(y,row);
     cout<<"#";
    }

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    hey man thats justr borland code u should tell him that also

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    here is some code hope u can fix the rest your self
    ***************************************

    #include <iostream.h>
    #include <stdlib.h>
    #include<iomanip.h>
    main()
    {
    int t;
    int y;
    cin>>y;
    cin>>t;
    for(int q=0;q<=y;q++)
    {
    cout<<"*\n";

    for(int e=0+2;e<=t;e++)
    {
    cout<<"*";
    }


    }
    system("pause");
    return 0;
    }

  7. #7
    Unregistered
    Guest
    Simple:

    Code:
    #include <iostream.h>
    #include <stdio.h>
    int main(void)
    {
    	int x,y;
            printf("Enter Width: ");
            cin >> x;
            printf("Enter Height: ");
            cin >> y;
            for(int n=0; n<y; n++)
            {
    		for(int h=0; h<x; h++)
                    {
                    	printf("*");
                    }
                    printf("\n");
      	}
            return(0);
    }
    Sorry, I hate scanf.

  8. #8
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    ^^that was me.^^
    just thought i should let ya know. make it look like im special or somthing...
    ..nevermind

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rectangle class
    By blackant in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2009, 08:33 AM
  2. segmetation fault (reading and writing file in c)
    By tasosa in forum C Programming
    Replies: 5
    Last Post: 04-13-2009, 06:04 AM
  3. Struct Program to find Point in Rectangle
    By DMJKobam in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2009, 08:56 PM
  4. Point passed rectangle...
    By Hunter2 in forum Game Programming
    Replies: 15
    Last Post: 10-10-2003, 09:57 AM
  5. Collision detection algorithm
    By Hannwaas in forum Game Programming
    Replies: 5
    Last Post: 11-30-2001, 12:27 PM

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