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!!