### DRAW WITH TEXT "T" SHAPE

http://img833.imageshack.us/img833/6472/semttulonem.png

I need help doing this shape, its kiling me. C++
Last edited on
what's up with those numbers? 3 to 51?
the size of the shape, it can be a T with 3x3 to 51x51 T
In this case the picture is 5x5
I do not see any interesting in this assignment. It is too primitive.
But i really need it, its so simple, but i cant do it :s

Got an exam tomorow, and they will ask me a thing like this.
This might be what you are looking for
http://www.cplusplus.com/reference/iomanip/setw/

using setw() you can set a certain amount of space before your output.
with that i can do it easely :p

but in exam i only can use while ; do while ; for......

and now, i got another to do, but is a litle diferent, but with same restrictions
http://img341.imageshack.us/img341/2057/semttuloohy.png
Last edited on
Could you post what you have come with so far? If I was doing it for the Bottom of the T i would do a for loop to put in the symbol with a while loop nested in it to add the space of half the number provided. Basically your width = oddnumber / 2, then output a blank space that many times then continue the for loop to output the symbol.
Last edited on
 ``1234567891011121314151617181920212223242526272829303132`` ``````#include #include using namespace std; int main(int argc, char *argv[]) { char a; int l,c; cout << "\nEnter one odd number ( 3 to 51): "; cin >> l; c=l/2; if (l%2==0 || l<3 || l>51) { cout << "ERRO!" << endl; system("PAUSE"); return EXIT_SUCCESS; } cout << "Enter the characther: "; cin >> a; for (int i=0; i
Here is a set up that gives the correct output but have no error handling etc. If you notice, your first for loop stays open into the other for which you do not want, you want to break apart the top and bottom, do the top of the T loop then execute the loop for the bottom. Also I used a while loop instead of if/else. On your lower for loop with the if/else what that is doing is putting the space there until it is correct then ends, it does not go all the way down just the first part (if that makes sense).
Here is the way I wrote it
 ``1234567891011121314151617181920212223242526272829303132`` ``````#include using namespace std; int main () { int number; int m = 0; //For the while loop to compare to width char character; cout << "Enter odd number" << endl; cin >> number; cout << " Enter Character" <> character; cout << "\n\n"; //Adds space between input and output int width = number / 2; //Sets the width to half to make a correct T for (int n = 0; n < number; n++) { cout << character; } for (int n = 0; n < number; n++) { cout << "\n"; //Skips to the next line while (m < width) { cout << " "; //Adds the whitespace m++; } m = 0; //Set it back to 0 for the next while loop execution cout << character; } return 0; }``````

Im sure you can edit and adapt as need be to get what you are looking for and be able to edit it to get what your looking for on the second problem.
Last edited on
Thank you, with this i think i can do all these kind of problems.
Oh I forgot to mention in your code you have:
`if (j=c)`

what this is doing is setting j to whatever value c was, basically the if statement does not compare, if you want it to compare if it equals it do this

`if (j == c)`

== compares, = assigns
Last edited on
Topic archived. No new replies allowed.