- Nov 28, 2000
- 2,224
- 0
- 0
Originally posted by: kamper
Originally posted by: notfred
I forget the syntax for cout, but the logic is correct.
for( int ii = 0; ii < height; ii++ ){
for( int jj = 0; jj < width; jj++ ){
if (ii == jj){
cout << "Z";
}
else{
cout << " ";
}
}
cout << "\n";
}
Maybe I'm reading that wrong but won't that draw a line from top-left to bottom-right?
Originally posted by: BingBongWongFooey[
edit: and remember to free() whatever you malloc() (or calloc() for that matter) after you're done with it; I forgot to.
edit2: nevermind, I forgot again that you're using c++. don't use malloc/free
Originally posted by: notfred
Originally posted by: kamper
Originally posted by: notfred
I forget the syntax for cout, but the logic is correct.
for( int ii = 0; ii < height; ii++ ){
for( int jj = 0; jj < width; jj++ ){
if (ii == jj){
cout << "Z";
}
else{
cout << " ";
}
}
cout << "\n";
}
Maybe I'm reading that wrong but won't that draw a line from top-left to bottom-right?
So reverse it. He said he was having trouble drawing a diagonal. If he wants to do it the ther direction, he olny has to change one line:
for( int jj = width; jj > 0; jj-- ){
Originally posted by: WarDemon666
omg. never thought of changing the for :S i also have to add a + 1 to count == linecount, or else its not aligned. thanks guys!
Originally posted by: notfred
Originally posted by: WarDemon666
omg. never thought of changing the for :S i also have to add a + 1 to count == linecount, or else its not aligned. thanks guys!
Yeah, to make your Z's go the other way, count down through them instead of up
It's obvious you're new to this, but once you get the hang of it, this kind of thing becomes intuitive.
Originally posted by: jediknight
Originally posted by: BingBongWongFooey[
edit: and remember to free() whatever you malloc() (or calloc() for that matter) after you're done with it; I forgot to.
edit2: nevermind, I forgot again that you're using c++. don't use malloc/free
Yes, it's new and delete, or new[] and delete[] (don't mix and match!)
Originally posted by: WarDemon666
Originally posted by: notfred
Originally posted by: WarDemon666
omg. never thought of changing the for :S i also have to add a + 1 to count == linecount, or else its not aligned. thanks guys!
Yeah, to make your Z's go the other way, count down through them instead of up
It's obvious you're new to this, but once you get the hang of it, this kind of thing becomes intuitive.
You think theres another way to do this? now im stuck on the X. lol. But you don't have to help, ill try and figure this one on my own
Originally posted by: WarDemon666
ah crap, i got the V, but its supposed to look like this:
edit: was messed up, check out the code
any ideas? gotta move it over one and add one in the middle at the end, but thats not 'good' programming is it?
Originally posted by: kamper
Originally posted by: WarDemon666
ah crap, i got the V, but its supposed to look like this:
edit: was messed up, check out the code
any ideas? gotta move it over one and add one in the middle at the end, but thats not 'good' programming is it?
Good work! If you can do the V you can probably handle most letters that have more than one line at a time. I think that your problem will depend entirely on whether or not an even or odd width is specified. If it's even you'll get that double at the bottom and there's not much you can do except modify the width (which would go against your requirements). Put in an odd width and it should line up nicely.
Originally posted by: kamper
I figured that a width of 5 would produce the V shown below. By saying that count = columns * 2 you've doubled your width, imo.
However, if this is what you want then I would change count = columns * 2 to count = (columns * 2) - 1. Or +1, depending on if you want round down or up.

 
				
		