Click here to Skip to main content
15,393,377 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make a symbol that will be printed as a "rectangle" according to the input
It is divided into two parts using functions
The first function prints the vertical column
The second function prints the remaining columns as a letter "U"
I wrote the first function, but I have a problem with the second function. I couldn't make the horizontal bars opposite
The output is shown to me as follows:


please enter the length and the width of the rctangle
4
4
aAaA
b
c
d
e
ffff

B
C
D
E

I want the output like this:

please enter the length and the width of the rctangle
4
4
aAaA
b B
c D
eEeE

I also have a problem with a character writing increment in horizontal bars,
how can I get rid of it?

What I have tried:

C++
#include <iostream>

using namespace std;



void edge_line(int row, int length)
{
  for (int col=0; col < length; ++col)
  {
    char c = 'a' - 32 * (col & 1);
    cout << c;
  }
    cout << '\n';
}
void middle_line(int row, int length){
    char c='b';
    for ( int col =1; col <=row ; col++)
        {
       cout<<c<<endl;
 c++;
}

for(intcol="0;" <length;++col)
{
chard="c-32" *(col&1);

cout<<c;
}
'\n';
cout<<endl;
cc="B" ;
for(inti="1;" ;i++){


cout<<cc<<endl;
cc++;
}

}

intmain()
{

width,length;
<<"pleaseenterthelengthandofrctangle"<<endl;
cin>> length>> width;
 edge_line(width , length);

middle_line(width , length);
return 0;

}
Posted
Updated 16-Dec-21 2:06am
v3

First off, indent your code: with a whole bunch flat to the left it's a lot harder to work out what is going on.
Secondly, make sure your code compiles before you post it here:
C++
width,length;
<<"pleaseenterthelengthandofrctangle"<<endl;
cin="">> length>> width;
The first line won't compile because the type specifiers - probably int are missing, and the middle line won't compile, probably because you missed the "cout" at the front:
C++
int width,length;
cout <<"pleaseenterthelengthandofrctangle"<<endl;
cin>> length>> width;


Get it compiling, and you stand a better chance of working code ...
   
Comments
User-15430256 16-Dec-21 3:53am
   
#include <iostream>

using namespace std;



void edge_line(int row, int length)
{
for (int col=0; col < length; ++col)
{
char c = 'a' - 32 * (col & 1);
cout << c;
}
cout << '\n';
}
void middle_line(int row, int length){
char c='b';
for ( int col =1; col <=row ; col++)
{
cout<<c<<endl;
c++;
="" }

="" for="" (int="" col="0;" <="" length;="" ++col)
="" {
="" char="" d="c-32" *(col="" &1="" )="" ;

="" cout="" <<="" c;
="" }
="" '\n';
="" cout<<endl;
="" cc="B" ;
for="" (="" int="" i="1;" ;="" i++){


="" cout<<cc<<endl;
="" cc++;
}

}

int="" main()
{

="" width="" ,length;
="" <<"please="" enter="" the="" length="" and="" of="" rctangle"<<endl;
="" cin="">> length>> width;
//uperline(width , length);
edge_line(width , length);

middle_line(width , length);
return 0;

}
User-15430256 16-Dec-21 3:54am
   
soory I copied the wrong code
Rick York 16-Dec-21 19:56pm
   
It is best to edit your original post and add a note to it stating that you have updated the code in the post.
You already posted this question at I have a problem with the code[^], and received some suggestions. Please do not repost. If you hace further information the update your original post. If you have qustions for the people who tried to help then use the Have a Question or Comment? link below the posted message.
   
Cannot keep observing you relentlessy abusing my code...
C++
#include <iostream>
using namespace std;

void edge_line(int row, int length);
void middle_line(int row, int length);

int main()
{
  int width ,length;
  cout <<"please enter the length and the width of the rctangle"<<endl;
  cin >> width>> length;

  edge_line(0, length);
  for (int row = 1; row < (width-1); ++row)
    middle_line(row, length);
  edge_line((width-1), length);
}


void edge_line(int row, int length)
{
  for (int col=0; col < length; ++col)
  {
    char c = 'a'+ row - 32 * (col & 1);
    cout << c;
  }
  cout << '\n';
}

void middle_line(int row, int length)
{
  for (int col=0; col < length; ++col)
  {
    char c = ' ';
    if ( col == 0 || col == (length-1))
    {
      c = 'a'+ row - 32 * (col & 1);
    }
    cout << c;
  }
  cout << '\n';
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900