anyone wanna help me with a little C++ coding?

Page 3 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: Walleye
here is my code as it exists now.

i'm writing through emacs while telneted to san marcos.

and the middle rows will not appear proper. it's like i never wrote them at all. i cant find what's causing that, what i'm doing wrong.

a few problems:

- you should calculate blank and blank1 after x and y have been entered
- when nesting loops, do not use the same variable for the loops.
- \b is backspace, if you wanna print a blank, use " "


also your code is formatted strangely...
 

agnitrate

Diamond Member
Jul 2, 2001
3,761
1
0
Why are you looping through k=1->k<=blankl twice but the second time is '/b'? What is '/b'? Obviously I've forgotten all the break characters :eek:

Secondly, not to sound like a dick, but look at my code with the spacing : image

Tell me what your program does in pseudo code. That's how you should start writing the code.

Let me explain how mine does it :

To print a rectangle, we loop through each row :
If it's the first or the last row, loop for as long as the length is and print # because these two rows are just full of # for as long as the length
Else, we're in any other row, so first print one #, loop and print length-2 spaces (because there is a # at the beginning and the end), then print one more #

You try with yours and see if it works out logically.

-silver
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: agnitrate
Why are you looping through k=1->k<=blankl twice but the second time is '/b'? What is '/b'? Obviously I've forgotten all the break characters :eek:

Secondly, not to sound like a dick, but look at my code with the spacing : image

Tell me what your program does in pseudo code. That's how you should start writing the code.

Let me explain how mine does it :

To print a rectangle, we loop through each row :
If it's the first or the last row, loop for as long as the length is and print # because these two rows are just full of # for as long as the length
Else, we're in any other row, so first print one #, loop and print length-2 spaces (because there is a # at the beginning and the end), then print one more #

You try with yours and see if it works out logically.

-silver
i dont go through blank line twice. it's blank line to signify that that's the lines. at the end of each blankl running is an end line.

blank is the # of blank spaces within a line. X - 2
 

agnitrate

Diamond Member
Jul 2, 2001
3,761
1
0
Ok, I see what you're trying to do with your code.

You did it like this :

For loop for first line
For loop for inbetween
For loop for last line

It looks like it could work so long as you changed "/b" to " ", you want a blank space. Try that and see if it works.

-silver
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: agnitrate
Ok, I see what you're trying to do with your code.

You did it like this :

For loop for first line
For loop for inbetween
For loop for last line

It looks like it could work so long as you changed "/b" to " ", you want a blank space. Try that and see if it works.

-silver

it doesnt.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: Walleye
Originally posted by: agnitrate
Ok, I see what you're trying to do with your code.

You did it like this :

For loop for first line
For loop for inbetween
For loop for last line

It looks like it could work so long as you changed "/b" to " ", you want a blank space. Try that and see if it works.

-silver

it doesnt.

did you read my post?
 

agnitrate

Diamond Member
Jul 2, 2001
3,761
1
0
Originally posted by: dighn

did you read my post?

^
|
|

He's right. You assign the variables before they're read in so it doesn't know what they are yet. Assign blank and its variants after your cins.

[edit] Actually, they both start @ -2 since you initialized them to 0. Which is the reason why your program compiles even though they haven't technically been read-in yet. I used to do that A LOT. [/edit]

-silver
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: dighn
Originally posted by: Walleye
Originally posted by: agnitrate
Ok, I see what you're trying to do with your code.

You did it like this :

For loop for first line
For loop for inbetween
For loop for last line

It looks like it could work so long as you changed "/b" to " ", you want a blank space. Try that and see if it works.

-silver

it doesnt.

did you read my post?

i took your suggestion too. it still didnt work :(

i probably placed them wrong...
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
it wont work with height. i can get width down, but it wont go beyond 3 as a height. just a sec, i'll see if it will do less than 3.
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
alright, all heights up to and including 3 work properly. 4 reverts to 3, as does anything else.
 

Krakerjak

Senior member
Jul 23, 2001
767
0
0
int r;
int blank;
int blank1;

cout....
cin....
cout....
cin....

blank = x-2;
blank1 = y-2;

cout....

for (i = 1; i <= x; i++)
cout << "#";
cout << endl;

for (k = 1; k <= blank1; k++)
{
cout << "#";
for (r = 1; r <= blank; r++) //*** make this change too
cout << " "; //*** and this one
cout << "#";
cout << endl;
}
for (h = 1; h <= x; h++)
cout << "#";

cout << endl;
cout << endl;

}
 

Krakerjak

Senior member
Jul 23, 2001
767
0
0
Originally posted by: Walleye
alright, all heights up to and including 3 work properly. 4 reverts to 3, as does anything else.

because you are using the same variable K in 2 for loops that are working together.
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: Krakerjak
Originally posted by: Walleye
alright, all heights up to and including 3 work properly. 4 reverts to 3, as does anything else.

because you are using the same variable K in 2 for loops that are working together.

THANK YOU!!!


woohoo, it's finally done, it's finally done!!!

*dances around singing*


well, that killed my afternoon, and evening... now to write the second program :(
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: Descartes
Originally posted by: Walleye
how do you rename in unix?

Are you frigging kidding? Are you willing do to ANYTHING yourself?

lol.

i thought it was rn...

then it tells me rn not found.

i know rm is remove... but..


oh fine, i'll google it.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: Walleye
Originally posted by: Descartes
Originally posted by: Walleye
how do you rename in unix?

Are you frigging kidding? Are you willing do to ANYTHING yourself?

lol.

i thought it was rn...

then it tells me rn not found.

i know rm is remove... but..


oh fine, i'll google it.

:D It would be quicker anyway.
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: Descartes
Originally posted by: dighn
ren oldfile newfile

Unix.

It's "mv", but he seriously needs to learn how to find some answers on his own.

alright... i'm taking a break. i'm ready to strangle my computer.... (would have done so many times by now if i ever found it's neck)