Creating 3*5 rectangle

I am trying to create a rectangle with 3*5 dimension which would look like:
#####
#####
#####
I wanted to use for, and do while loop for that programming. I couldn't been able to create my desired dimension of 3*5.
Could anyone please help me out on this please. Thank you all.

//complier directives

#include<iostream>

#include<cstdlib>

using namespace std;

//main body

int main ()
{
//local identifiers
int length,width,Done;
char character,Again;
//input module

cout<<"Please enter the length and width of the rectangle seperated by a space:\n";
cin>>length>>width;
cout<<"Please enter your design character: \t";
cin>>character;
for(int i=0; i<length; i++)
{
for(int j=0; j<width; j++)
cout<<character;
cout<<endl;
}//end i loop
int i=0,j=0;

do
{
j=0;

do
{
cout << character;
}while(j++<width);
cout << endl;

}while(i++<length);
cout<<endl;
system("PAUSE");
system("CLS");
return 0;
}//end of the program
closed account (Dy7SLyTq)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main(int argc, char *argv[])
{
	int Width, Height;
	
	cout<<"Width: ";
	cin>> Width;
	
	cout<<"Height: ";
	cin>> Height;
	
	for(int Counter = 0; Counter < Height; Counter++)
	{
		for(int Counter = 0; Counter < Width; Counter++)
			cout<<"#";
			
		cout<< endl;
	}
}


you might have to switch width and height.
Thanks for your help. But is there any way to fix the problem using whatever i have up there?but i do appreciate your help though. Thanks alot
I understand that but with all information I have provided up there, Is there a way I could get rectangle with 3*5 rows column using DO WHILE please. Can anyone help me out please.. I am stuck up in the middle
the code you have works, but you don't need the do while loop.

your code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<cstdlib>
using namespace std;

//main body

int main()
{

	int length, width, Done;
	char character, Again;


	cout << "Please enter the length and width of the rectangle seperated by a space:\n";
	cin >> length >> width;
	cin.ignore(1000, '\n');
	cout << endl;

	cout << "Please enter your design character: \t";
	cin >> character;
	cin.ignore(1000, '\n');
	cout << endl;

	for (int i = 0; i < length; i++)
	{
		for (int j = 0; j < width; j++)
			cout << character;
		
		cout << endl;
	}

	cin.ignore();
	return 0;
}


my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <iomanip>

int main()
{
	int length = 0, height = 0;
	char drawCharacter;

	std::cout << "Please enter the height: ";
	std::cin >> height;
	std::cin.clear();
	std::cin.ignore(1000, '\n');
	std::cout << std::endl;

	std::cout << "Please enter the length: ";
	std::cin >> length;
	std::cin.clear();
	std::cin.ignore(1000, '\n');
	std::cout << std::endl;

	std::cout << "Please enter the draw character: ";
	std::cin >> drawCharacter;
	std::cin.clear();
	std::cin.ignore(1000, '\n');
	std::cout << std::endl;

	for (int i = 0; i < height; i++)
	{
		std::cout << std::setfill(drawCharacter) << std::setw(length + 1) << ' ' << std::endl;
	}

	std::cin.ignore();
	return 0;

}
Last edited on
Topic archived. No new replies allowed.