Thread: Rectangle Generator....help!

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    14

    Question Rectangle Generator....help!

    Hi, so i made this program to practice program flow/loops. It allows you to put in a length and width, which it uses to print out a certain number of dashes "-" and "|" characters.
    The only problem is the "spaceFuncion" will not work, as it will not print out the side lengths to be more than 1 character a part (even if you enter a length of 10). Please help me out!!

    HERE'S THE MAIN.cpp PAGE:

    Code:
    // Rectangle generator.cpp : main project file.
    
    #include "stdafx.h"
    
    using namespace std;
    
    /////////////////////MAIN/////////////////////////////////
    int main()
    {
    	cout << "============================================================\n";
    	cout << "============================================================\n";
    	cout << "==========={} WELCOME TO THE RECTNAGLE PROGRAM {}===========\n";
    	int length;
    	int width;
    
    	/////////////ENTER PARAMETERS///////////////////////
    	cout << "\nWhat is the Length of your rectangle: ";
    	cin >> length;
    	cout << endl;
    	cout << "\nWhat is the width of your rectangle: ";
    	cin >> width;
    	cout << endl;
    
    	/////////CONSTRUCTS/DRAWS a rectangle/////////////
    	Rectangle rectangle(length, width);
    
    
        char response;
    	cin >> response;
        return 0;
    }
    
    ///////Definitions//////////
    	/////////Constructor/////////////
    Rectangle::Rectangle(int LENGTH, int WIDTH)
    {
    	length = LENGTH;
    	width = WIDTH;
    
    ///////TOP///////////
    	for(int i=length;i>=1;i--)
    	{
    		cout << "-";
    	}
    
    	cout << endl;
    
    //////SIDES/////////////////
    	for(int i=width;i>=1;i--)
    	{
    		cout << "|";
    		/////See space funciion below  ~|
    		spaceFunction(LENGTH);   //    \|/
    		cout <<"|\n";
    	}
    
    ///////BOTTOM///////////////////
    	for(int i=length;i>=1;i--)
    	{
    		cout << "-";
    	}
    
    	cout << endl;
    }
    
    ///////FILLS RECTANGLE WITH "+" signs//////////
    void spaceFunction(int length)
    {
    	int LENGTH = length;
    	for(int i=LENGTH;i>=1;i--);
    	{
    		cout << "+";
    	}
    }
    And here's the HEADER FILE:

    Code:
    //////////////// HEADER FILE //////////////////////
    #pragma once
    #include <iostream>
    
    using namespace std;
    
    /////////////////RECTANGLE CLASS ///////////////////
    class Rectangle
    {
    public:
    	//////DRAWS rectangle////////////
    	Rectangle(int LENGTH, int WIDTH);
    		~Rectangle() {}
    
    		int GETlength() {return length;}
    		void SETlength(int Length) {length = Length;}
    
    		int GETwidth() {return width;}
    		void SETwidth(int Width) {width = Width;}
    
    
    protected:
    	int length;
    	int width;
    };
    
    ///////Fills rectangle with + signs/////////////
    void spaceFunction(int length);
    Thanks!!

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You have to put on your glasses.

    Code:
    	for(int i=LENGTH;i>=1;i--);
    	{
    		cout << "+";
    	}
    You'll also need to make sure how many +s you actually need to output.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    14
    Wow haha, you'll have to forgive me because im currently only in my second week of programming (Sams C++),
    BUT THANK YOU!
    =)

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. GUI structure in C
    By officedog in forum C Programming
    Replies: 36
    Last Post: 11-19-2008, 02:33 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, 01:27 PM

Tags for this Thread