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
//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;
i=0;
do
{
cout << character;
}while((j++<width)&&(i++<length));
cout << endl;
cout<<"Do you have another length and width to process <Y or N>?\t";
cin>>Again;
if((Again=='Y')||(Again=='y'))
{
system("PAUSE")
system("CLS")
}//end of if
}while((Again=='Y')||(Again=='y'));
return 0;
}//end of the program
In your first input module after you did cout<<character you should continue with << " " instead of a newline; the newline cout << endl; should be just after your second for loop, while still in the first for loop, at then end of it actually. In your second do{} statement, just outputting character to cout will give you only a single line, I'm not sure that's what you want but if you follow my first guideline you'll have your rectangle.
Thank you AeonFlux1212
I am new with this for, do while loops so I am confused on what you mean?
Is there a way you could elaborate or anything to help out?
I am just stuck here with no clue of what to do next.
Please help me only if you could...no pressure and I am very thankful for your support. I really appreciate that.
so your character will print j times (width) for each row (length). This is where your rectangle will be printed out. The rest of your code is not necessary, unless you really want to print out a menu that ables you to print another rectangle, with another character for example. So this part,
1 2 3 4 5 6 7
j=0;
i=0;
do
{
cout << character;
}while((j++<width)&&(i++<length));
is unnecessary. Instead of that should be this part:
1 2 3 4 5 6 7 8 9 10
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